

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Easyviz &mdash; Easyviz Documentation v1.0 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '1.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="Easyviz Documentation v1.0 documentation" href="index.html" />
    <link rel="prev" title="Welcome to Easyviz Documentation!" href="index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="index.html" title="Welcome to Easyviz Documentation!"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Easyviz Documentation v1.0 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="easyviz">
<h1>Easyviz<a class="headerlink" href="#easyviz" title="Permalink to this headline">¶</a></h1>
<p>Easyviz is a unified interface to various packages for scientific
visualization and plotting.  The Easyviz interface is written in
Python with the purpose of making it very easy to visualize data in
Python scripts. Both curve plots and more advanced 2D/3D visualization
of scalar and vector fields are supported.  The Easyviz interface was
designed with three ideas in mind: 1) a simple, Matlab-like syntax; 2)
a unified interface to lots of visualization engines (called backends
later): Gnuplot, Matplotlib, Grace, Veusz, Pmw.Blt.Graph, PyX,
Matlab, VTK, VisIt, OpenDX; and 3) a minimalistic interface which
offers only basic control of plots: curves, linestyles, legends,
title, axis extent and names.  More fine-tuning of plots can be done
by invoking backend-specific commands.</p>
<p>Easyviz was made so that one can postpone the choice of a particular
visualization package (and its special associated syntax). This is
often useful when you quickly need to visualize curves or 2D/3D fields
in your Python program, but haven&#8217;t really decided which plotting tool
to go for. As Python is gaining popularity at universities, students
are often forced to continuously switch between Matlab and Python,
which is straightforward for array computing, but (previously)
annoying for plotting. Easyviz was therefore also made to ease the
switch between Python and Matlab.</p>
<p>If you encounter problems with using Easyviz, please visit the
<em>Troubleshooting</em> chapter and the <em>Installation</em> chapter at the
end of the documentation.</p>
<div class="section" id="easyviz-documentation">
<h2>Easyviz Documentation<a class="headerlink" href="#easyviz-documentation" title="Permalink to this headline">¶</a></h2>
<p>The present documentation is available in a number of formats:</p>
<blockquote>
<ul class="simple">
<li><a class="reference external" href="https://scitools.googlecode.com/svn/trunk/doc/easyviz/easyviz.pdf">PDF</a></li>
<li><a class="reference external" href="http://www.simula.no/~hpl/easyviz/easyviz.html">Plain HTML</a></li>
<li><a class="reference external" href="http://www.simula.no/~hpl/easyviz/easyviz_sphinx_html/html/index.html">Sphinx HTML</a></li>
<li><a class="reference external" href="https://scitools.googlecode.com/svn/trunk/doc/easyviz/easyviz.txt">Plain text</a></li>
<li><a class="reference external" href="http://code.google.com/p/scitools/wiki/EasyvizDocumentation">Wiki</a></li>
<li><a class="reference external" href="https://scitools.googlecode.com/svn/trunk/doc/easyviz/easyviz.do.txt">Doconce source</a></li>
</ul>
</blockquote>
<p>The documentation is written in the <a class="reference external" href="http://code.google.com/p/doconce">Doconce</a>
format and can be translated into a number of different formats (reST,
Sphinx, LaTeX, HTML, XML, OpenOffice, RTF, Word, and plain untagged ASCII).</p>
</div>
<div class="section" id="guiding-principles">
<h2>Guiding Principles<a class="headerlink" href="#guiding-principles" title="Permalink to this headline">¶</a></h2>
<p><em>First principle.</em> Array data can be plotted with a minimal
set of keystrokes using a Matlab-like syntax. A simple</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">t</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">51</span><span class="p">)</span>    <span class="c"># 51 points between 0 and 3</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
</pre></div>
</div>
<p>plots the data in (the NumPy array) <tt class="docutils literal"><span class="pre">t</span></tt> versus the data in (the NumPy
array) <tt class="docutils literal"><span class="pre">y</span></tt>. If you need legends, control of the axis, as well as
additional curves, all this is obtained by the standard Matlab-style
commands</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">y2</span> <span class="o">=</span> <span class="n">t</span><span class="o">**</span><span class="mi">4</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="c"># pick out each 4 points and add random noise:</span>
<span class="n">t3</span> <span class="o">=</span> <span class="n">t</span><span class="p">[::</span><span class="mi">4</span><span class="p">]</span>
<span class="n">y3</span> <span class="o">=</span> <span class="n">y2</span><span class="p">[::</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="mf">0.02</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">t3</span><span class="p">))</span>

<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="s">&#39;r-&#39;</span><span class="p">)</span>
<span class="n">hold</span><span class="p">(</span><span class="s">&#39;on&#39;</span><span class="p">)</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="s">&#39;b-&#39;</span><span class="p">)</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t3</span><span class="p">,</span> <span class="n">y3</span><span class="p">,</span> <span class="s">&#39;bo&#39;</span><span class="p">)</span>
<span class="n">legend</span><span class="p">(</span><span class="s">&#39;t^2*exp(-t^2)&#39;</span><span class="p">,</span> <span class="s">&#39;t^4*exp(-t^2)&#39;</span><span class="p">,</span> <span class="s">&#39;data&#39;</span><span class="p">)</span>
<span class="n">title</span><span class="p">(</span><span class="s">&#39;Simple Plot Demo&#39;</span><span class="p">)</span>
<span class="n">axis</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.05</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">])</span>
<span class="n">xlabel</span><span class="p">(</span><span class="s">&#39;t&#39;</span><span class="p">)</span>
<span class="n">ylabel</span><span class="p">(</span><span class="s">&#39;y&#39;</span><span class="p">)</span>
<span class="n">show</span><span class="p">()</span>

<span class="n">hardcopy</span><span class="p">(</span><span class="s">&#39;tmp0.ps&#39;</span><span class="p">)</span>  <span class="c"># this one can be included in LaTeX</span>
<span class="n">hardcopy</span><span class="p">(</span><span class="s">&#39;tmp0.png&#39;</span><span class="p">)</span> <span class="c"># this one can be included in HTML</span>
</pre></div>
</div>
<p>Easyviz also allows these additional function calls to be executed
as a part of the <tt class="docutils literal"><span class="pre">plot</span></tt> call:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="s">&#39;r-&#39;</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="s">&#39;b-&#39;</span><span class="p">,</span> <span class="n">t3</span><span class="p">,</span> <span class="n">y3</span><span class="p">,</span> <span class="s">&#39;bo&#39;</span><span class="p">,</span>
     <span class="n">legend</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;t^2*exp(-t^2)&#39;</span><span class="p">,</span> <span class="s">&#39;t^4*exp(-t^2)&#39;</span><span class="p">,</span> <span class="s">&#39;data&#39;</span><span class="p">),</span>
     <span class="n">title</span><span class="o">=</span><span class="s">&#39;Simple Plot Demo&#39;</span><span class="p">,</span>
     <span class="n">axis</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.05</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">),</span>
     <span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;y&#39;</span><span class="p">,</span>
     <span class="n">hardcopy</span><span class="o">=</span><span class="s">&#39;tmp1.ps&#39;</span><span class="p">,</span>
     <span class="n">show</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

<span class="n">hardcopy</span><span class="p">(</span><span class="s">&#39;tmp0.png&#39;</span><span class="p">)</span> <span class="c"># this one can be included in HTML</span>
</pre></div>
</div>
<p>A scalar function <img class="math" src="_images/math/f6fa69bf141527c27a71998fbb0bfd4a8493fce6.png" alt="f(x,y)"/> may be visualized
as an elevated surface with colors using these commands:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">x</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">41</span><span class="p">)</span>  <span class="c"># 41 point on [-2, 2]</span>
<span class="n">xv</span><span class="p">,</span> <span class="n">yv</span> <span class="o">=</span> <span class="n">ndgrid</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>    <span class="c"># define a 2D grid with points (xv,yv)</span>
<span class="n">values</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">)</span>       <span class="c"># function values</span>
<span class="n">surfc</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span>
      <span class="n">shading</span><span class="o">=</span><span class="s">&#39;interp&#39;</span><span class="p">,</span>
      <span class="n">clevels</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span>
      <span class="n">clabels</span><span class="o">=</span><span class="s">&#39;on&#39;</span><span class="p">,</span>
      <span class="n">hidden</span><span class="o">=</span><span class="s">&#39;on&#39;</span><span class="p">,</span>
      <span class="n">show</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<p><em>Second princple.</em> Easyviz is just a unified interface to other
plotting packages that can be called from Python. Such plotting
packages are referred to as backends. Several backends are supported:
Gnuplot, Matplotlib, Grace (Xmgr), Veusz, Pmw.Blt.Graph, PyX, Matlab,
VTK, VisIt, OpenDX. In other words, scripts that use Easyviz commands
only, can work with a variety of backends, depending on what you have
installed on the machine in question and what quality of the plots you
demand. For example, switching from Gnuplot to Matplotlib is trivial.</p>
<p>Scripts with Easyviz commands will most probably run anywhere since at
least the Gnuplot package can always be installed right away on any
platform. In practice this means that when you write a script to
automate investigation of a scientific problem, you can always quickly
plot your data with Easyviz (i.e., Matlab-like) commands and postpone
to marry any specific plotting tool. Most likely, the choice of
plotting backend can remain flexible. This will also allow old scripts
to work with new fancy plotting packages in the future if Easyviz
backends are written for those packages.</p>
<p><em>Third principle.</em> The Easyviz interface is minimalistic, aimed at
rapid prototyping of plots. This makes the Easyviz code easy to read
and extend (e.g., with new backends). If you need more sophisticated
plotting, like controlling tickmarks, inserting annotations, etc., you
must grab the backend object and use the backend-specific syntax to
fine-tune the plot. The idea is that you can get away with Easyviz and
a plotting package-independent script &#8220;95 percent&#8221; of the time - only
now and then there will be demand for package-dependent code for
fine-tuning and customization of figures.</p>
<p>These three principles and the Easyviz implementation make simple things
simple and unified, and complicated things are not more complicated than
they would otherwise be. You can always start out with the simple
commands - and jump to complicated fine-tuning only when strictly needed.</p>
</div>
</div>
<div class="section" id="tutorial">
<h1>Tutorial<a class="headerlink" href="#tutorial" title="Permalink to this headline">¶</a></h1>
<p>This tutorial starts with plotting a single curve with a simple
<tt class="docutils literal"><span class="pre">plot(x,y)</span></tt> command. Then we add a legend, axis labels, a title, etc.
Thereafter we show how multiple curves are plotted together. We also
explain how line styles and axis range can be controlled. The
next section deals with animations and making movie files. More advanced
topics such as fine tuning of plots (using plotting package-specific
commands) and working with Axis and Figure objects close the curve
plotting part of the tutorial.</p>
<p>Various methods for visualization of scalar fields in 2D and 3D are
treated next, before we show how 2D and 3D vector fields can be handled.</p>
<div class="section" id="plotting-a-single-curve">
<h2>Plotting a Single Curve<a class="headerlink" href="#plotting-a-single-curve" title="Permalink to this headline">¶</a></h2>
<p>Let us plot the curve <img class="math" src="_images/math/da31d0a76d1bd5fe9ffcfecb1a134ccd15efb468.png" alt="y = t^2\exp(-t^2)"/> for
<img class="math" src="_images/math/e0d2bf360290fd61d1c1557e763f2622363b3d35.png" alt="t"/> values between 0 and 3.  First we generate equally spaced
coordinates for <img class="math" src="_images/math/e0d2bf360290fd61d1c1557e763f2622363b3d35.png" alt="t"/>, say 51 values (50 intervals). Then we compute the
corresponding <img class="math" src="_images/math/092e364e1d9d19ad5fffb0b46ef4cc7f2da02c1c.png" alt="y"/> values at these points, before we call the
<tt class="docutils literal"><span class="pre">plot(t,y)</span></tt> command to make the curve plot.  Here is the complete
program:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">scitools.std</span> <span class="kn">import</span> <span class="o">*</span>

<span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">t</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>

<span class="n">t</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">51</span><span class="p">)</span>    <span class="c"># 51 points between 0 and 3</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">t</span><span class="p">))</span>         <span class="c"># allocate y with float elements</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">t</span><span class="p">)):</span>
    <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>

<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
</pre></div>
</div>
<p>The first line imports all of SciTools and Easyviz that can be handy
to have when doing scientific computations. In this program we
pre-allocate the <tt class="docutils literal"><span class="pre">y</span></tt> array and fill it with values, element by
element, in a Python loop. Alternatively, we may operate
on the whole <tt class="docutils literal"><span class="pre">t</span></tt> array at once, which yields faster and shorter code:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">scitools.std</span> <span class="kn">import</span> <span class="o">*</span>

<span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">t</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>

<span class="n">t</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">51</span><span class="p">)</span>    <span class="c"># 51 points between 0 and 3</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>                  <span class="c"># compute all f values at once</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">f</span></tt> function can also be skipped, if desired, so that we can write
directly</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">y</span> <span class="o">=</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
<p>To include the plot in electronic documents, we need a hardcopy of the
figure in PostScript, PNG, or another image format.  The <tt class="docutils literal"><span class="pre">hardcopy</span></tt>
command produces files with images in various formats:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">hardcopy</span><span class="p">(</span><span class="s">&#39;tmp1.eps&#39;</span><span class="p">)</span> <span class="c"># produce PostScript</span>
<span class="n">hardcopy</span><span class="p">(</span><span class="s">&#39;tmp1.png&#39;</span><span class="p">)</span> <span class="c"># produce PNG</span>
</pre></div>
</div>
<p>The filename extension determines the format: <tt class="docutils literal"><span class="pre">.ps</span></tt> or
<tt class="docutils literal"><span class="pre">.eps</span></tt> for PostScript, and <tt class="docutils literal"><span class="pre">.png</span></tt> for PNG.
Figure <a class="reference internal" href="#fig-plot1a"><em>A simple plot in PostScript format.</em></a> displays the resulting plot.</p>
<div class="figure" id="fig-plot1a">
<img alt="_images/plot1a.png" src="_images/plot1a.png" />
<p class="caption">A simple plot in PostScript format.</p>
</div>
<p>On some platforms, some backends may result in a plot that is shown in
just a fraction of a second on the screen before the plot window disappears
(using the Gnuplot backend on Windows machines or using the Matplotlib
backend constitute two examples). To make the window stay on the screen,
add</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nb">raw_input</span><span class="p">(</span><span class="s">&#39;Press the Return key to quit: &#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>at the end of the program. The plot window is killed when the program
terminates, and this satement postpones the termination until the user
hits the Return key.</p>
</div>
<div class="section" id="decorating-the-plot">
<h2>Decorating the Plot<a class="headerlink" href="#decorating-the-plot" title="Permalink to this headline">¶</a></h2>
<p>The <img class="math" src="_images/math/26eeb5258ca5099acf8fe96b2a1049c48c89a5e6.png" alt="x"/> and <img class="math" src="_images/math/092e364e1d9d19ad5fffb0b46ef4cc7f2da02c1c.png" alt="y"/> axis in curve plots should have labels, here <img class="math" src="_images/math/e0d2bf360290fd61d1c1557e763f2622363b3d35.png" alt="t"/> and
<img class="math" src="_images/math/092e364e1d9d19ad5fffb0b46ef4cc7f2da02c1c.png" alt="y"/>, respectively. Also, the curve should be identified with a label,
or legend as it is often called.  A title above the plot is also
common.  In addition, we may want to control the extent of the axes (although
most plotting programs will automatically adjust the axes to the range of the
data).
All such things are easily added after the <tt class="docutils literal"><span class="pre">plot</span></tt> command:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">xlabel</span><span class="p">(</span><span class="s">&#39;t&#39;</span><span class="p">)</span>
<span class="n">ylabel</span><span class="p">(</span><span class="s">&#39;y&#39;</span><span class="p">)</span>
<span class="n">legend</span><span class="p">(</span><span class="s">&#39;t^2*exp(-t^2)&#39;</span><span class="p">)</span>
<span class="n">axis</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.05</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">])</span>   <span class="c"># [tmin, tmax, ymin, ymax]</span>
<span class="n">title</span><span class="p">(</span><span class="s">&#39;My First Easyviz Demo&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>This syntax is inspired by Matlab to make the switch between
Easyviz and Matlab almost trivial.
Easyviz has also introduced a more &#8220;Pythonic&#8221; <tt class="docutils literal"><span class="pre">plot</span></tt> command where
all the plot properties can be set at once:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span>
     <span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;t&#39;</span><span class="p">,</span>
     <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;y&#39;</span><span class="p">,</span>
     <span class="n">legend</span><span class="o">=</span><span class="s">&#39;t^2*exp(-t^2)&#39;</span><span class="p">,</span>
     <span class="n">axis</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.05</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">],</span>
     <span class="n">title</span><span class="o">=</span><span class="s">&#39;My First Easyviz Demo&#39;</span><span class="p">,</span>
     <span class="n">hardcopy</span><span class="o">=</span><span class="s">&#39;tmp1.eps&#39;</span><span class="p">,</span>
     <span class="n">show</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<p>With <tt class="docutils literal"><span class="pre">show=False</span></tt> one can avoid the plot window on the screen and
just make the hardcopy. This feature is particularly useful if
one generates a large number of plots in a loop.</p>
<p>Note that we in the curve legend write <tt class="docutils literal"><span class="pre">t</span></tt> square as <tt class="docutils literal"><span class="pre">t^2</span></tt> (LaTeX style)
rather than <tt class="docutils literal"><span class="pre">t**2</span></tt> (program style). Whichever form you choose is up to
you, but the LaTeX form sometimes looks better in some plotting
programs (Gnuplot is one example).
See Figure <a class="reference internal" href="#fig-plot1c"><em>A single curve with label, title, and axis adjusted.</em></a> for what the modified
plot looks like and how <tt class="docutils literal"><span class="pre">t^2</span></tt> is typeset in Gnuplot.</p>
<div class="figure" id="fig-plot1c">
<img alt="_images/plot1c.png" src="_images/plot1c.png" />
<p class="caption">A single curve with label, title, and axis adjusted.</p>
</div>
</div>
<div class="section" id="plotting-multiple-curves">
<h2>Plotting Multiple Curves<a class="headerlink" href="#plotting-multiple-curves" title="Permalink to this headline">¶</a></h2>
<p>A common plotting task is to compare two or more curves, which
requires multiple curves to be drawn in the same plot.
Suppose we want to plot the two functions <img class="math" src="_images/math/4a4945ef7ed4318fcfb6c12fd53b3989297dbd10.png" alt="f_1(t)=t^2\exp(-t^2)"/>
and <img class="math" src="_images/math/fb8174c5ce2ae3011a211bbee95c89f9cfcd319a.png" alt="f_2(t)=t^4\exp(-t^2)"/>. If we write two <tt class="docutils literal"><span class="pre">plot</span></tt> commands after
each other, two separate plots will be made. To make the second
<tt class="docutils literal"><span class="pre">plot</span></tt> command draw the curve in the first plot, we need to
issue a <tt class="docutils literal"><span class="pre">hold('on')</span></tt> command. Alternatively, we can provide all
data in a single <tt class="docutils literal"><span class="pre">plot</span></tt> command. A complete program illustrates the
different approaches:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">scitools.std</span> <span class="kn">import</span> <span class="o">*</span>   <span class="c"># for curve plotting</span>

<span class="k">def</span> <span class="nf">f1</span><span class="p">(</span><span class="n">t</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">f2</span><span class="p">(</span><span class="n">t</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">f1</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>

<span class="n">t</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">51</span><span class="p">)</span>
<span class="n">y1</span> <span class="o">=</span> <span class="n">f1</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
<span class="n">y2</span> <span class="o">=</span> <span class="n">f2</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>

<span class="c"># Matlab-style syntax:</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y1</span><span class="p">)</span>
<span class="n">hold</span><span class="p">(</span><span class="s">&#39;on&#39;</span><span class="p">)</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y2</span><span class="p">)</span>

<span class="n">xlabel</span><span class="p">(</span><span class="s">&#39;t&#39;</span><span class="p">)</span>
<span class="n">ylabel</span><span class="p">(</span><span class="s">&#39;y&#39;</span><span class="p">)</span>
<span class="n">legend</span><span class="p">(</span><span class="s">&#39;t^2*exp(-t^2)&#39;</span><span class="p">,</span> <span class="s">&#39;t^4*exp(-t^2)&#39;</span><span class="p">)</span>
<span class="n">title</span><span class="p">(</span><span class="s">&#39;Plotting two curves in the same plot&#39;</span><span class="p">)</span>
<span class="n">hardcopy</span><span class="p">(</span><span class="s">&#39;tmp2.eps&#39;</span><span class="p">)</span>

<span class="c"># alternative:</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;y&#39;</span><span class="p">,</span>
     <span class="n">legend</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;t^2*exp(-t^2)&#39;</span><span class="p">,</span> <span class="s">&#39;t^4*exp(-t^2)&#39;</span><span class="p">),</span>
     <span class="n">title</span><span class="o">=</span><span class="s">&#39;Plotting two curves in the same plot&#39;</span><span class="p">,</span>
     <span class="n">hardcopy</span><span class="o">=</span><span class="s">&#39;tmp2.eps&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The sequence of the multiple legends is such that the first legend
corresponds to the first curve, the second legend to the second curve,
and so on. The visual result appears in Figure <a class="reference internal" href="#fig-plot2a"><em>Two curves in the same plot.</em></a>.</p>
<p>Doing a <tt class="docutils literal"><span class="pre">hold('off')</span></tt> makes the next <tt class="docutils literal"><span class="pre">plot</span></tt> command create a new
plot.</p>
<div class="figure" id="fig-plot2a">
<img alt="_images/plot2a.png" src="_images/plot2a.png" />
<p class="caption">Two curves in the same plot.</p>
</div>
</div>
<div class="section" id="controlling-line-styles">
<h2>Controlling Line Styles<a class="headerlink" href="#controlling-line-styles" title="Permalink to this headline">¶</a></h2>
<p>When plotting multiple curves in the same plot, the individual curves
get distinct default line styles, depending on the program that is
used to produce the curve (and the settings for this program). It
might well happen that you get a green and a red curve (which is bad
for a significant portion of the male population).  Therefore,
we often want to control the line style in detail. Say we want the first
curve (<tt class="docutils literal"><span class="pre">t</span></tt> and <tt class="docutils literal"><span class="pre">y1</span></tt>) to be drawn as a red solid line and the second
curve (<tt class="docutils literal"><span class="pre">t</span></tt> and <tt class="docutils literal"><span class="pre">y2</span></tt>) as blue circles at the discrete data points.  The
Matlab-inspired syntax for specifying line types applies a letter for
the color and a symbol from the keyboard for the line type. For
example, <tt class="docutils literal"><span class="pre">r-</span></tt> represents a red (<tt class="docutils literal"><span class="pre">r</span></tt>) line (<tt class="docutils literal"><span class="pre">-</span></tt>), while <tt class="docutils literal"><span class="pre">bo</span></tt> means blue
(<tt class="docutils literal"><span class="pre">b</span></tt>) circles (<tt class="docutils literal"><span class="pre">o</span></tt>). The line style specification is added as an
argument after the <img class="math" src="_images/math/26eeb5258ca5099acf8fe96b2a1049c48c89a5e6.png" alt="x"/> and <img class="math" src="_images/math/092e364e1d9d19ad5fffb0b46ef4cc7f2da02c1c.png" alt="y"/> coordinate arrays of the curve:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="s">&#39;r-&#39;</span><span class="p">)</span>
<span class="n">hold</span><span class="p">(</span><span class="s">&#39;on&#39;</span><span class="p">)</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="s">&#39;bo&#39;</span><span class="p">)</span>

<span class="c"># or</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="s">&#39;r-&#39;</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="s">&#39;bo&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The effect of controlling the line styles can be seen in
Figure <a class="reference internal" href="#fig-plot2c"><em>Two curves in the same plot, with controlled line styles.</em></a>.</p>
<div class="figure" id="fig-plot2c">
<img alt="_images/plot2c.png" src="_images/plot2c.png" />
<p class="caption">Two curves in the same plot, with controlled line styles.</p>
</div>
<p>Assume now that we want to plot the blue circles at every 4 points only.
We can grab every 4 points out of the <tt class="docutils literal"><span class="pre">t</span></tt> array by using an appropriate
slice: <tt class="docutils literal"><span class="pre">t2</span> <span class="pre">=</span> <span class="pre">t[::4]</span></tt>. Note that the first colon means the range from the
first to the last data point, while the second colon separates this
range from the stride, i.e., how many points we should &#8220;jump over&#8221;
when we pick out a set of values of the array.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">scitools.std</span> <span class="kn">import</span> <span class="o">*</span>

<span class="k">def</span> <span class="nf">f1</span><span class="p">(</span><span class="n">t</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">f2</span><span class="p">(</span><span class="n">t</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">f1</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>

<span class="n">t</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">51</span><span class="p">)</span>
<span class="n">y1</span> <span class="o">=</span> <span class="n">f1</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
<span class="n">t2</span> <span class="o">=</span> <span class="n">t</span><span class="p">[::</span><span class="mi">4</span><span class="p">]</span>
<span class="n">y2</span> <span class="o">=</span> <span class="n">f2</span><span class="p">(</span><span class="n">t2</span><span class="p">)</span>

<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="s">&#39;r-6&#39;</span><span class="p">,</span> <span class="n">t2</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="s">&#39;bo3&#39;</span><span class="p">,</span>
     <span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;y&#39;</span><span class="p">,</span>
     <span class="n">axis</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">],</span>
     <span class="n">legend</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;t^2*exp(-t^2)&#39;</span><span class="p">,</span> <span class="s">&#39;t^4*exp(-t^2)&#39;</span><span class="p">),</span>
     <span class="n">title</span><span class="o">=</span><span class="s">&#39;Plotting two curves in the same plot&#39;</span><span class="p">,</span>
     <span class="n">hardcopy</span><span class="o">=</span><span class="s">&#39;tmp2.eps&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>In this plot we also adjust the size of the line and the circles by
adding an integer: <tt class="docutils literal"><span class="pre">r-6</span></tt> means a red line with thickness 6 and <tt class="docutils literal"><span class="pre">bo5</span></tt>
means red circles with size 5. The effect of the given line thickness
and symbol size depends on the underlying plotting program. For
the Gnuplot program one can view the effect in Figure <a class="reference internal" href="#fig-plot2g"><em>Circles at every 4 points and extended line thickness (6) and circle size (3).</em></a>.</p>
<div class="figure" id="fig-plot2g">
<img alt="_images/plot2g.png" src="_images/plot2g.png" />
<p class="caption">Circles at every 4 points and extended line thickness (6) and circle size (3).</p>
</div>
<dl class="docutils">
<dt>The different available line colors include</dt>
<dd><ul class="first last simple">
<li>yellow:   <tt class="docutils literal"><span class="pre">'y'</span></tt></li>
<li>magenta:  <tt class="docutils literal"><span class="pre">'m'</span></tt></li>
<li>cyan:     <tt class="docutils literal"><span class="pre">'c'</span></tt></li>
<li>red:      <tt class="docutils literal"><span class="pre">'r'</span></tt></li>
<li>green:    <tt class="docutils literal"><span class="pre">'g'</span></tt></li>
<li>blue:     <tt class="docutils literal"><span class="pre">'b'</span></tt></li>
<li>white:    <tt class="docutils literal"><span class="pre">'w'</span></tt></li>
<li>black:    <tt class="docutils literal"><span class="pre">'k'</span></tt></li>
</ul>
</dd>
<dt>The different available line types are</dt>
<dd><ul class="first last simple">
<li>solid line:      <tt class="docutils literal"><span class="pre">'-'</span></tt></li>
<li>dashed line:     <tt class="docutils literal"><span class="pre">'--'</span></tt></li>
<li>dotted line:     <tt class="docutils literal"><span class="pre">':'</span></tt></li>
<li>dash-dot line:   <tt class="docutils literal"><span class="pre">'-.'</span></tt></li>
</ul>
</dd>
</dl>
<p>During programming, you can find all these details in the
documentation of the <tt class="docutils literal"><span class="pre">plot</span></tt> function. Just type <tt class="docutils literal"><span class="pre">help(plot)</span></tt>
in an interactive Python shell or invoke <tt class="docutils literal"><span class="pre">pydoc</span></tt> with
<tt class="docutils literal"><span class="pre">scitools.easyviz.plot</span></tt>. This tutorial is available
through <tt class="docutils literal"><span class="pre">pydoc</span> <span class="pre">scitools.easyviz</span></tt>.</p>
<p>We remark that in the Gnuplot program all the different line types are
drawn as solid lines on the screen. The hardcopy chooses automatically
different line types (solid, dashed, etc.) and not in accordance with
the line type specification.</p>
<dl class="docutils">
<dt>Lots of markers at data points are available:</dt>
<dd><ul class="first last simple">
<li>plus sign:                     <tt class="docutils literal"><span class="pre">'+'</span></tt></li>
<li>circle:                        <tt class="docutils literal"><span class="pre">'o'</span></tt></li>
<li>asterisk:                      <tt class="docutils literal"><span class="pre">'*'</span></tt></li>
<li>point:                         <tt class="docutils literal"><span class="pre">'.'</span></tt></li>
<li>cross:                         <tt class="docutils literal"><span class="pre">'x'</span></tt></li>
<li>square:                        <tt class="docutils literal"><span class="pre">'s'</span></tt></li>
<li>diamond:                       <tt class="docutils literal"><span class="pre">'d'</span></tt></li>
<li>upward-pointing triangle:      <tt class="docutils literal"><span class="pre">'^'</span></tt></li>
<li>downward-pointing triangle:    <tt class="docutils literal"><span class="pre">'v'</span></tt></li>
<li>right-pointing triangle:       <tt class="docutils literal"><span class="pre">'&gt;'</span></tt></li>
<li>left-pointing triangle:        <tt class="docutils literal"><span class="pre">'&lt;'</span></tt></li>
<li>five-point star (pentagram):   <tt class="docutils literal"><span class="pre">'p'</span></tt></li>
<li>six-point star (hexagram):     <tt class="docutils literal"><span class="pre">'h'</span></tt></li>
<li>no marker (default): <tt class="xref docutils literal"><span class="pre">None</span></tt></li>
</ul>
</dd>
</dl>
<p>Symbols and line styles may be combined, for instance as in <tt class="docutils literal"><span class="pre">'kx-'</span></tt>,
which means a black solid line with black crosses at the data points.</p>
<p><em>Another Example.</em> Let us extend the previous example with a third
curve where the data points are slightly randomly distributed around
the <img class="math" src="_images/math/df9cc80af3d9483c1c014d7f3138d07bf1e775d7.png" alt="f_2(t)"/> curve:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">scitools.std</span> <span class="kn">import</span> <span class="o">*</span>

<span class="k">def</span> <span class="nf">f1</span><span class="p">(</span><span class="n">t</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">f2</span><span class="p">(</span><span class="n">t</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">f1</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>

<span class="n">t</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">51</span><span class="p">)</span>
<span class="n">y1</span> <span class="o">=</span> <span class="n">f1</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
<span class="n">y2</span> <span class="o">=</span> <span class="n">f2</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>

<span class="c"># pick out each 4 points and add random noise:</span>
<span class="n">t3</span> <span class="o">=</span> <span class="n">t</span><span class="p">[::</span><span class="mi">4</span><span class="p">]</span>      <span class="c"># slice, stride 4</span>
<span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">11</span><span class="p">)</span>  <span class="c"># fix random sequence</span>
<span class="n">noise</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="mf">0.02</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">t3</span><span class="p">))</span>
<span class="n">y3</span> <span class="o">=</span> <span class="n">y2</span><span class="p">[::</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="n">noise</span>

<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="s">&#39;r-&#39;</span><span class="p">)</span>
<span class="n">hold</span><span class="p">(</span><span class="s">&#39;on&#39;</span><span class="p">)</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="s">&#39;ks-&#39;</span><span class="p">)</span>   <span class="c"># black solid line with squares at data points</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t3</span><span class="p">,</span> <span class="n">y3</span><span class="p">,</span> <span class="s">&#39;bo&#39;</span><span class="p">)</span>

<span class="n">legend</span><span class="p">(</span><span class="s">&#39;t^2*exp(-t^2)&#39;</span><span class="p">,</span> <span class="s">&#39;t^4*exp(-t^2)&#39;</span><span class="p">,</span> <span class="s">&#39;data&#39;</span><span class="p">)</span>
<span class="n">title</span><span class="p">(</span><span class="s">&#39;Simple Plot Demo&#39;</span><span class="p">)</span>
<span class="n">axis</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.05</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">])</span>
<span class="n">xlabel</span><span class="p">(</span><span class="s">&#39;t&#39;</span><span class="p">)</span>
<span class="n">ylabel</span><span class="p">(</span><span class="s">&#39;y&#39;</span><span class="p">)</span>
<span class="n">show</span><span class="p">()</span>
<span class="n">hardcopy</span><span class="p">(</span><span class="s">&#39;tmp3.eps&#39;</span><span class="p">)</span>
<span class="n">hardcopy</span><span class="p">(</span><span class="s">&#39;tmp3.png&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The plot is shown in Figure <a class="reference internal" href="#fig-plot3"><em>A plot with three curves.</em></a>.</p>
<div class="figure" id="fig-plot3">
<img alt="_images/plot3.png" src="_images/plot3.png" />
<p class="caption">A plot with three curves.</p>
</div>
<p><em>Minimalistic Typing.</em> When exploring mathematics in the interactive Python shell, most of us
are interested in the quickest possible commands.
Here is an example of minimalistic syntax for
comparing the two sample functions we have used in the previous examples:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">t</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">51</span><span class="p">)</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="p">),</span> <span class="n">t</span><span class="p">,</span> <span class="n">t</span><span class="o">**</span><span class="mi">4</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
</pre></div>
</div>
<p><em>Text.</em> A text can be placed at a point <img class="math" src="_images/math/e53b1fe25be1c679117fb44a6a886fe1247d189a.png" alt="(x,y)"/> using the call</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">text</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s">&#39;Some text&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p><em>More Examples.</em> The examples in this tutorial, as well as
additional examples, can be found in the <tt class="docutils literal"><span class="pre">examples</span></tt> directory in the
root directory of the SciTools source code tree.</p>
</div>
<div class="section" id="interactive-plotting-sessions">
<h2>Interactive Plotting Sessions<a class="headerlink" href="#interactive-plotting-sessions" title="Permalink to this headline">¶</a></h2>
<p>All the Easyviz commands can of course be issued in an interactive
Python session. The only thing to comment is that the <tt class="docutils literal"><span class="pre">plot</span></tt> command
returns a result:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">51</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
<span class="go">[&lt;scitools.easyviz.common.Line object at 0xb5727f6c&gt;]</span>
</pre></div>
</div>
<p>Most users will just ignore this output line.</p>
<p>All Easyviz commands that produce a plot return an object reflecting the
particular type of plot. The <tt class="docutils literal"><span class="pre">plot</span></tt> command returns a list of
<tt class="docutils literal"><span class="pre">Line</span></tt> objects, one for each curve in the plot. These <tt class="docutils literal"><span class="pre">Line</span></tt>
objects can be invoked to see, for instance, the value of different
parameters in the plot:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">line</span><span class="p">,</span> <span class="o">=</span> <span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s">&#39;b&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">getp</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
<span class="go">{&#39;description&#39;: &#39;&#39;,</span>
<span class="go"> &#39;dims&#39;: (4, 1, 1),</span>
<span class="go"> &#39;legend&#39;: &#39;&#39;,</span>
<span class="go"> &#39;linecolor&#39;: &#39;b&#39;,</span>
<span class="go"> &#39;pointsize&#39;: 1.0,</span>
<span class="go"> ...</span>
</pre></div>
</div>
<p>Such output is mostly of interest to advanced users.</p>
</div>
<div class="section" id="making-animations">
<span id="easyviz-movie"></span><h2>Making Animations<a class="headerlink" href="#making-animations" title="Permalink to this headline">¶</a></h2>
<p>A sequence of plots can be combined into an animation and stored in a
movie file. First we need to generate a series of hardcopies, i.e.,
plots stored in files.  Thereafter we must use a tool to combine the
individual plot files into a movie file.</p>
<p><em>Example.</em> The function
<img class="math" src="_images/math/aac665c5f2b5c8ae4ffbfdbc8f310a92d568bba7.png" alt="f(x; m, s) = (2\pi)^{-1/2}s^{-1}\exp{\left[-{1\over2}\left({x-m\over s}\right)^2\right]}"/>
is known as the Gaussian function or the probability density function
of the normal (or Gaussian) distribution.  This bell-shaped function is
&#8220;wide&#8221; for large <img class="math" src="_images/math/f37bba504894945c07a32f5496d74299a37aa51c.png" alt="s"/> and &#8220;peak-formed&#8221; for small <img class="math" src="_images/math/f37bba504894945c07a32f5496d74299a37aa51c.png" alt="s"/>, see Figure
<a class="reference internal" href="#fig-plot4"><em>Different shapes of a Gaussian function.</em></a>. The function is symmetric around <img class="math" src="_images/math/25c8e0d1b87454ca2081044f6bbf3011aad1b413.png" alt="x=m"/> (<img class="math" src="_images/math/2e275495e7e44d279fb3e5051b3a63115e79ead5.png" alt="m=0"/> in the
figure).  Our goal is to make an animation where we see how this
function evolves as <img class="math" src="_images/math/f37bba504894945c07a32f5496d74299a37aa51c.png" alt="s"/> is decreased. In Python we implement the
formula above as a function <tt class="docutils literal"><span class="pre">f(x,</span> <span class="pre">m,</span> <span class="pre">s)</span></tt>.</p>
<div class="figure" id="fig-plot4">
<img alt="_images/plot4.png" src="_images/plot4.png" />
<p class="caption">Different shapes of a Gaussian function.</p>
</div>
<p>The animation is created by varying <img class="math" src="_images/math/f37bba504894945c07a32f5496d74299a37aa51c.png" alt="s"/> in a loop and for each <img class="math" src="_images/math/f37bba504894945c07a32f5496d74299a37aa51c.png" alt="s"/>
issue a <tt class="docutils literal"><span class="pre">plot</span></tt> command. A moving curve is then visible on the screen.
One can also make a movie file that can be played as any other
computer movie using a standard movie player. To this end, each plot
is saved to a file, and all the files are combined together using some
suitable tool, which is reached through the <tt class="docutils literal"><span class="pre">movie</span></tt> function in
Easyviz. All necessary steps will be apparent in the complete program
below, but before diving into the code we need to comment upon a
couple of issues with setting up the <tt class="docutils literal"><span class="pre">plot</span></tt> command for animations.</p>
<p>The underlying plotting program will normally adjust the axis to the
maximum and minimum values of the curve if we do not specify the axis
ranges explicitly. For an animation such automatic axis adjustment is
misleading - the axis ranges must be fixed to avoid a jumping
axis. The relevant values for the axis range is the minimum and
maximum value of <img class="math" src="_images/math/bb2c93730dbb48558bb3c4738c956c4e8f816437.png" alt="f"/>. The minimum value is zero, while the maximum
value appears for <img class="math" src="_images/math/25c8e0d1b87454ca2081044f6bbf3011aad1b413.png" alt="x=m"/> and increases with decreasing <img class="math" src="_images/math/f37bba504894945c07a32f5496d74299a37aa51c.png" alt="s"/>. The range
of the <img class="math" src="_images/math/092e364e1d9d19ad5fffb0b46ef4cc7f2da02c1c.png" alt="y"/> axis must therefore be <img class="math" src="_images/math/ebe8ab9bcb691d7b2a2acad5f660bc068d973648.png" alt="[0,f(m; m, \min s)]"/>.</p>
<p>The function <img class="math" src="_images/math/bb2c93730dbb48558bb3c4738c956c4e8f816437.png" alt="f"/> is defined for all <img class="math" src="_images/math/c7a38fe1882faf425767fabbf7727e46a18ed221.png" alt="-\infty &lt; x &lt; \infty"/>, but the
function value is very small already <img class="math" src="_images/math/f28de6b767ea937f3cfc80afb5bb23fb903a9964.png" alt="3s"/> away from <img class="math" src="_images/math/25c8e0d1b87454ca2081044f6bbf3011aad1b413.png" alt="x=m"/>. We may therefore
limit the <img class="math" src="_images/math/26eeb5258ca5099acf8fe96b2a1049c48c89a5e6.png" alt="x"/> coordinates to <img class="math" src="_images/math/17ce4d7454c8f455021c7d55900cfee4b4903fe8.png" alt="[m-3s,m+3s]"/>.</p>
<p>Now we are ready to take a look at the complete code
for animating how the Gaussian function evolves as the <img class="math" src="_images/math/f37bba504894945c07a32f5496d74299a37aa51c.png" alt="s"/> parameter
is decreased from 2 to 0.2:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">scitools.std</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">import</span> <span class="nn">time</span>

<span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">s</span><span class="p">):</span>
    <span class="k">return</span> <span class="p">(</span><span class="mf">1.0</span><span class="o">/</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">)</span><span class="o">*</span><span class="n">s</span><span class="p">))</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="mf">0.5</span><span class="o">*</span><span class="p">((</span><span class="n">x</span><span class="o">-</span><span class="n">m</span><span class="p">)</span><span class="o">/</span><span class="n">s</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>

<span class="n">m</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">s_start</span> <span class="o">=</span> <span class="mi">2</span>
<span class="n">s_stop</span> <span class="o">=</span> <span class="mf">0.2</span>
<span class="n">s_values</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="n">s_start</span><span class="p">,</span> <span class="n">s_stop</span><span class="p">,</span> <span class="mi">30</span><span class="p">)</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="n">m</span> <span class="o">-</span><span class="mi">3</span><span class="o">*</span><span class="n">s_start</span><span class="p">,</span> <span class="n">m</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">s_start</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span>
<span class="c"># f is max for x=m; smaller s gives larger max value</span>
<span class="n">max_f</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">s_stop</span><span class="p">)</span>

<span class="c"># show the movie on the screen</span>
<span class="c"># and make hardcopies of frames simultaneously:</span>
<span class="n">counter</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">s_values</span><span class="p">:</span>
    <span class="n">y</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span>
    <span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">x</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="o">-</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">max_f</span><span class="p">],</span>
         <span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;f&#39;</span><span class="p">,</span> <span class="n">legend</span><span class="o">=</span><span class="s">&#39;s=</span><span class="si">%4.2f</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">s</span><span class="p">,</span>
         <span class="n">hardcopy</span><span class="o">=</span><span class="s">&#39;tmp</span><span class="si">%04d</span><span class="s">.png&#39;</span> <span class="o">%</span> <span class="n">counter</span><span class="p">)</span>
    <span class="n">counter</span> <span class="o">+=</span> <span class="mi">1</span>
    <span class="c">#time.sleep(0.2)  # can insert a pause to control movie speed</span>

<span class="c"># make movie file the simplest possible way:</span>
<span class="n">movie</span><span class="p">(</span><span class="s">&#39;tmp*.png&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that the <img class="math" src="_images/math/f37bba504894945c07a32f5496d74299a37aa51c.png" alt="s"/> values are decreasing (<tt class="docutils literal"><span class="pre">linspace</span></tt> handles this
automatically if the start value is greater than the stop value).
Also note that we, simply because we think it is visually more
attractive, let the <img class="math" src="_images/math/092e364e1d9d19ad5fffb0b46ef4cc7f2da02c1c.png" alt="y"/> axis go from -0.1 although the <img class="math" src="_images/math/bb2c93730dbb48558bb3c4738c956c4e8f816437.png" alt="f"/> function is
always greater than zero.</p>
<p><em>Remarks on Filenames.</em> For each frame (plot) in the movie we store the plot in a file.  The
different files need different names and an easy way of referring to
the set of files in right order. We therefore suggest to use filenames
of the form <tt class="docutils literal"><span class="pre">tmp0001.png</span></tt>, <tt class="docutils literal"><span class="pre">tmp0002.png</span></tt>, <tt class="docutils literal"><span class="pre">tmp0003.png</span></tt>, etc.  The
printf format <tt class="docutils literal"><span class="pre">04d</span></tt> pads the integers with zeros such that <tt class="docutils literal"><span class="pre">1</span></tt> becomes
<tt class="docutils literal"><span class="pre">0001</span></tt>, <tt class="docutils literal"><span class="pre">13</span></tt> becomes <tt class="docutils literal"><span class="pre">0013</span></tt> and so on.  The expression <tt class="docutils literal"><span class="pre">tmp*.png</span></tt> will
now expand (by an alphabetic sort) to a list of all files in proper
order. Without the padding with zeros, i.e., names of the form
<tt class="docutils literal"><span class="pre">tmp1.png</span></tt>, <tt class="docutils literal"><span class="pre">tmp2.png</span></tt>, ..., <tt class="docutils literal"><span class="pre">tmp12.png</span></tt>, etc., the alphabetic order
will give a wrong sequence of frames in the movie. For instance,
<tt class="docutils literal"><span class="pre">tmp12.png</span></tt> will appear before <tt class="docutils literal"><span class="pre">tmp2.png</span></tt>.</p>
<p>Note that the names of plot files specified when making hardopies must
be consistent with the specification of names in the call to <tt class="docutils literal"><span class="pre">movie</span></tt>.
Typically, one applies a Unix wildcard notation in the call to
<tt class="docutils literal"><span class="pre">movie</span></tt>, say <tt class="docutils literal"><span class="pre">plotfile*.eps</span></tt>, where the asterisk will match any set of
characters. When specifying hardcopies, we must then use a filename
that is consistent with <tt class="docutils literal"><span class="pre">plotfile*.eps</span></tt>, that is, the filename must
start with <tt class="docutils literal"><span class="pre">plotfile</span></tt> and end with <tt class="docutils literal"><span class="pre">.eps</span></tt>, but in between
these two parts we are free to construct (e.g.) a frame number padded
with zeros.</p>
<p>We recommend to always remove previously generated plot files before
a new set of files is made. Otherwise, the movie may get old and new
files mixed up. The following Python code removes all files
of the form <tt class="docutils literal"><span class="pre">tmp*.png</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">glob</span><span class="o">,</span> <span class="nn">os</span>
<span class="k">for</span> <span class="n">filename</span> <span class="ow">in</span> <span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="s">&#39;tmp*.png&#39;</span><span class="p">):</span>
    <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
</pre></div>
</div>
<p>These code lines should be inserted at the beginning of the code example
above. Alternatively, one may store all plotfiles in a subfolder
and later delete the subfolder. Here is a suitable code segment:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">shutil</span><span class="o">,</span> <span class="nn">os</span>
<span class="n">subdir</span> <span class="o">=</span> <span class="s">&#39;temp&#39;</span>  <span class="c"># subfolder for plot files</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">subdir</span><span class="p">):</span>  <span class="c"># does the subfolder already exist?</span>
    <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">subdir</span><span class="p">)</span>  <span class="c"># delete the whole folder</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">subdir</span><span class="p">)</span> <span class="c"># make new subfolder</span>
<span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="n">subdir</span><span class="p">)</span> <span class="c"># move to subfolder</span>
<span class="c"># do all the plotting</span>
<span class="c"># make movie</span>
<span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">pardir</span><span class="p">)</span>  <span class="c"># optional: move up to parent folder</span>
</pre></div>
</div>
<p><em>Movie Formats.</em> Having a set of (e.g.) <tt class="docutils literal"><span class="pre">tmp*.png</span></tt> files, one can simply generate a movie by
a <tt class="docutils literal"><span class="pre">movie('tmp*.png')</span></tt> call. The <tt class="docutils literal"><span class="pre">movie</span></tt> function generates a movie
file called <tt class="docutils literal"><span class="pre">movie.avi</span></tt> (AVI format), <tt class="docutils literal"><span class="pre">movie.mpeg</span></tt> (MPEG format), or
<tt class="docutils literal"><span class="pre">movie.gif</span></tt> (animated GIF format) in the current working
directory. The movie format depends on the encoders found on your
machine.</p>
<p>You can get complete control of the movie format and the
name of the movie file by supplying more arguments to the
<tt class="docutils literal"><span class="pre">movie</span></tt> function. First, let us generate an animated GIF
file called <tt class="docutils literal"><span class="pre">tmpmovie.gif</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">movie</span><span class="p">(</span><span class="s">&#39;tmp_*.eps&#39;</span><span class="p">,</span> <span class="n">encoder</span><span class="o">=</span><span class="s">&#39;convert&#39;</span><span class="p">,</span> <span class="n">fps</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
      <span class="n">output_file</span><span class="o">=</span><span class="s">&#39;tmpmovie.gif&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The generation of animated GIF images applies the <tt class="docutils literal"><span class="pre">convert</span></tt> program
from the ImageMagick suite. This program must of course be installed
on the machine. The argument fps stands for frames per second so
here the speed of the movie is slow in that there is a delay of half
a second between each frame (image file).
To view the animated GIF file, one can use the <tt class="docutils literal"><span class="pre">animate</span></tt>
program (also from ImageMagick) and give the movie file as command-line
argument. One can alternatively put the GIF file in a web page
in an IMG tag such that a browser automatically displays the movie.</p>
<p>An AVI movie can be generated by the call</p>
<div class="highlight-python"><pre>movie('tmp_*.eps', encoder='ffmpeg', fps=4,
      output_file='tmpmovie1.avi',</pre>
</div>
<p>Alternatively, we may generate an MPEG movie using
the <tt class="docutils literal"><span class="pre">ppmtompeg</span></tt> encoder from the Netpbm suite of
image manipulation tools:</p>
<div class="highlight-python"><pre>movie('tmp_*.eps', encoder='ppmtompeg', fps=24,
      output_file='tmpmovie2.mpeg',</pre>
</div>
<p>The <tt class="docutils literal"><span class="pre">ppmtompeg</span></tt> supports only a few (high) frame rates.</p>
<p>The next sample call to <tt class="docutils literal"><span class="pre">movie</span></tt> uses the Mencoder tool and specifies
some additional arguments (video codec, video bitrate, and the
quantization scale):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">movie</span><span class="p">(</span><span class="s">&#39;tmp_*.eps&#39;</span><span class="p">,</span> <span class="n">encoder</span><span class="o">=</span><span class="s">&#39;mencoder&#39;</span><span class="p">,</span> <span class="n">fps</span><span class="o">=</span><span class="mi">24</span><span class="p">,</span>
      <span class="n">output_file</span><span class="o">=</span><span class="s">&#39;tmpmovie.mpeg&#39;</span><span class="p">,</span>
      <span class="n">vcodec</span><span class="o">=</span><span class="s">&#39;mpeg2video&#39;</span><span class="p">,</span> <span class="n">vbitrate</span><span class="o">=</span><span class="mi">2400</span><span class="p">,</span> <span class="n">qscale</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
</pre></div>
</div>
<p>Playing movie files can be done by a lot of programs. Windows Media
Player is a default choice on Windows machines. On Unix, a variety
of tools can be used. For animated GIF files the <tt class="docutils literal"><span class="pre">animate</span></tt> program
from the ImageMagick suite is suitable, or one can simply
show the file in a web page with the HTML command
<tt class="docutils literal"><span class="pre">&lt;img</span> <span class="pre">src=&quot;tmpmovie.gif&quot;&gt;</span></tt>. AVI and MPEG files can be played by,
for example, the
<tt class="docutils literal"><span class="pre">myplayer</span></tt>, <tt class="docutils literal"><span class="pre">vlc</span></tt>, or <tt class="docutils literal"><span class="pre">totem</span></tt> programs.</p>
</div>
<div class="section" id="advanced-easyviz-topics">
<h2>Advanced Easyviz Topics<a class="headerlink" href="#advanced-easyviz-topics" title="Permalink to this headline">¶</a></h2>
<p>The information in the previous sections aims at being sufficient for
the daily work with plotting curves. Sometimes, however, one wants to
fine-control the plot or how Easyviz behaves. First, we explain how to
set the backend. Second, we tell how to speed up the
<tt class="docutils literal"><span class="pre">from</span> <span class="pre">scitools.std</span> <span class="pre">import</span> <span class="pre">*</span></tt> statement.  Third, we show how to operate with
the plotting program directly and using plotting program-specific
advanced features. Fourth, we explain how the user can grab <tt class="docutils literal"><span class="pre">Figure</span></tt>
and <tt class="docutils literal"><span class="pre">Axis</span></tt> objects that Easyviz produces &#8220;behind the curtain&#8221;.</p>
<p><em>Controlling the Backend.</em> The Easyviz backend can either be set in a configuration file (see
&#8220;Setting Parameters in the Configuration File&#8221; below), by
importing a special backend in the program, or by adding a
command-line option</p>
<div class="highlight-python"><pre>--SCITOOLS_easyviz_backend name</pre>
</div>
<p>where <tt class="docutils literal"><span class="pre">name</span></tt> is the name of the backend: <tt class="docutils literal"><span class="pre">gnuplot</span></tt>, <tt class="docutils literal"><span class="pre">vtk</span></tt>,
<tt class="docutils literal"><span class="pre">matplotlib</span></tt>, etc. Which backend you choose depends on what you have
available on your computer system and what kind of plotting
functionality you want.</p>
<p>An alternative method is to import a specific backend in a program. Instead
of the <tt class="docutils literal"><span class="pre">from</span> <span class="pre">scitools.std</span> <span class="pre">import</span> <span class="pre">*</span></tt> statement one writes</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">numpy</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">scitools.easyviz.gnuplot_</span> <span class="kn">import</span> <span class="o">*</span>  <span class="c"># work with Gnuplot</span>
<span class="c"># or</span>
<span class="kn">from</span> <span class="nn">scitools.easyviz.vtk_</span> <span class="kn">import</span> <span class="o">*</span>      <span class="c"># work with VTK</span>
</pre></div>
</div>
<p>Note the trailing underscore in the module names for the various backends.</p>
<p>The following program prints a list of the names of the
available backends on your computer system:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">scitools.std</span> <span class="kn">import</span> <span class="o">*</span>
<span class="n">backends</span> <span class="o">=</span> <span class="n">available_backends</span><span class="p">()</span>
<span class="k">print</span> <span class="s">&#39;Available backends:&#39;</span><span class="p">,</span> <span class="n">backends</span>
</pre></div>
</div>
<p>There will be quite some output explaining the missing backends and
what must be installed to use these backends. Be prepared for exceptions
and error messages too.</p>
<p><em>Importing Just Easyviz.</em> The <tt class="docutils literal"><span class="pre">from</span> <span class="pre">scitools.std</span> <span class="pre">import</span> <span class="pre">*</span></tt> statement imports many modules and packages:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">numpy</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">scitools.numpyutils</span> <span class="kn">import</span> <span class="o">*</span>  <span class="c"># some convenience functions</span>
<span class="kn">from</span> <span class="nn">numpy.lib.scimath</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">scipy</span> <span class="kn">import</span> <span class="o">*</span>                <span class="c"># if scipy is installed</span>
<span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">operator</span><span class="o">,</span> <span class="nn">math</span>
<span class="kn">from</span> <span class="nn">scitools.StringFunction</span> <span class="kn">import</span> <span class="n">StringFunction</span>
<span class="kn">from</span> <span class="nn">glob</span> <span class="kn">import</span> <span class="n">glob</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">scipy</span></tt> import can take some time and lead to slow start-up of plot
scripts. A more minimalistic import for curve plotting is</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">scitools.easyviz</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">numpy</span> <span class="kn">import</span> <span class="o">*</span>
</pre></div>
</div>
<p>Alternatively, one can edit the SciTools configuration file as
explained below in the section &#8220;Setting Parameters in the
Configuration File&#8221;.</p>
<p><em>Setting Parameters in the Configuration File.</em> Easyviz is a subpackage of SciTools, and the the SciTools
configuration file, called <tt class="docutils literal"><span class="pre">scitools.cfg</span></tt> has several sections
(<tt class="docutils literal"><span class="pre">[easyviz]</span></tt>, <tt class="docutils literal"><span class="pre">[gnuplot]</span></tt>, and <tt class="docutils literal"><span class="pre">[matplotlib]</span></tt>) where parameters
controlling the behavior of plotting can be set. For example, the
backend for Easyviz can be controlled with the <tt class="docutils literal"><span class="pre">backend</span></tt> parameter:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">easyviz</span><span class="p">]</span>
<span class="n">backend</span> <span class="o">=</span> <span class="n">vtk</span>
</pre></div>
</div>
<p>Similarly, Matplotlib&#8217;s use of LaTeX can be controlled by a boolean
parameter:</p>
<div class="highlight-python"><pre>[matplotlib]
text.usetex = &lt;bool&gt; false</pre>
</div>
<p>The text <tt class="docutils literal"><span class="pre">&lt;bool&gt;</span></tt> indicates that this is a parameter with a boolean</p>
<p>A configuration file with name <tt class="docutils literal"><span class="pre">.scitools.cfg</span></tt> file can be placed in
the current working folder, thereby affecting plots made in this
folder, or it can be located in the user&#8217;s home folder, which will
affect all plotting sessions for the user in question. There is also a
common SciTools config file <tt class="docutils literal"><span class="pre">scitools.cfg</span></tt> for the whole site, located
in the directory where the <tt class="docutils literal"><span class="pre">scitools</span></tt> package is installed. It is
recommended to copy the <tt class="docutils literal"><span class="pre">scitools.cfg</span></tt>, either from installation or
the SciTools source folder <tt class="docutils literal"><span class="pre">lib/scitools</span></tt>, to <tt class="docutils literal"><span class="pre">.scitools.cfg</span></tt>
in your home folder. Then you can easily control the Easyviz backend
and other paramteres by editing your local <tt class="docutils literal"><span class="pre">.scitools.cfg</span></tt> file.</p>
<p>Parameters set in the configuration file can also be set directly
on the command line when running a program. The name of the
command-line option is</p>
<div class="highlight-python"><div class="highlight"><pre><span class="o">--</span><span class="n">SCITOOLS_sectionname_parametername</span>
</pre></div>
</div>
<p>where <tt class="docutils literal"><span class="pre">sectionname</span></tt> is the name of the section in the file
and <tt class="docutils literal"><span class="pre">parametername</span></tt> is the name of the
parameter. For example, setting the <tt class="docutils literal"><span class="pre">backend</span></tt> parameter in the
<tt class="docutils literal"><span class="pre">[easyviz]</span></tt> section by</p>
<div class="highlight-python"><pre>--SCITOOLS_easyviz_backend gnuplot</pre>
</div>
<p>Here is an example where we use Matplotlib as backend, turn on
the use of LaTeX in Matplotlib, and avoid the potentially slow import
of SciPy:</p>
<div class="highlight-python"><pre>python myprogram.py --SCITOOLS_easyviz_backend matplotlib \
    --SCITOOLS_matplotlib_text.usetex true --SCITOOLS_scipy_load no</pre>
</div>
<p><em>Working with the Plotting Program Directly.</em> Easyviz supports just the most common plotting commands, typically the
commands you use &#8220;95 percent&#8221; of the time when exploring curves.
Various plotting packages have lots of additional commands for
different advanced features.  When Easyviz does not have a command
that supports a particular feature, one can grab the Python object
that communicates with the underlying plotting program (known as
&#8220;backend&#8221;) and work with this object directly, using plotting
program-specific command syntax.  Let us illustrate this principle
with an example where we add a text and an arrow in the plot, see
Figure <a class="reference internal" href="#fig-plot2i"><em>Illustration of a text and an arrow using Gnuplot-specific commands.</em></a>.</p>
<div class="figure" id="fig-plot2i">
<img alt="_images/plot2i.png" src="_images/plot2i.png" />
<p class="caption">Illustration of a text and an arrow using Gnuplot-specific commands.</p>
</div>
<p>Easyviz does not support arrows at arbitrary places inside the plot,
but Gnuplot does. If we use Gnuplot as backend, we may grab the
<tt class="docutils literal"><span class="pre">Gnuplot</span></tt> object and issue Gnuplot commands to this object
directly. Here is an example of the typical recipe, written after the
core of the plot is made in the ordinary (plotting
program-independent) way:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">g</span> <span class="o">=</span> <span class="n">get_backend</span><span class="p">()</span>
<span class="k">if</span> <span class="n">backend</span> <span class="o">==</span> <span class="s">&#39;gnuplot&#39;</span><span class="p">:</span>
    <span class="c"># g is a Gnuplot object, work with Gnuplot commands directly:</span>
    <span class="n">g</span><span class="p">(</span><span class="s">&#39;set label &quot;global maximum&quot; at 0.1,0.5 font &quot;Times,18&quot;&#39;</span><span class="p">)</span>
    <span class="n">g</span><span class="p">(</span><span class="s">&#39;set arrow from 0.5,0.48 to 0.98,0.37 linewidth 2&#39;</span><span class="p">)</span>
    <span class="n">g</span><span class="o">.</span><span class="n">refresh</span><span class="p">()</span>
    <span class="n">g</span><span class="o">.</span><span class="n">hardcopy</span><span class="p">(</span><span class="s">&#39;tmp2.eps&#39;</span><span class="p">)</span>  <span class="c"># make new hardcopy</span>

    <span class="n">g</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>               <span class="c"># new plot</span>
    <span class="n">data</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">Data</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span><span class="o">**</span><span class="mi">3</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="p">),</span> <span class="n">with_</span><span class="o">=</span><span class="s">&#39;points 3 3&#39;</span><span class="p">,</span>
                        <span class="n">title</span><span class="o">=</span><span class="s">&#39;t**3*exp(-t)&#39;</span><span class="p">)</span>
    <span class="n">func</span> <span class="o">=</span> <span class="n">Gnuplot</span><span class="o">.</span><span class="n">Func</span><span class="p">(</span><span class="s">&#39;t**4*exp(-t)&#39;</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="s">&#39;t**4*exp(-t)&#39;</span><span class="p">)</span>
    <span class="n">g</span><span class="p">(</span><span class="s">&#39;set tics border font &quot;Courier,14&quot;&#39;</span><span class="p">)</span>
    <span class="n">g</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
<p>For the available features and the syntax of commands, we refer to
the Gnuplot manual and the emp{demo.py} program in Python interface to
Gnuplot.
The idea advocated here is that you can quickly generate
plots with Easyviz using standard commands that are independent of
the underlying plotting package. However, when you need advanced
features, you must add plotting package-specific code as shown
above. This principle makes Easyviz a light-weight interface, but
without limiting the available functionality of various plotting programs.</p>
<p>The file <tt class="docutils literal"><span class="pre">grab_backend_demo.py</span></tt> in the <tt class="docutils literal"><span class="pre">examples</span></tt> folder of the
SciTools source code contains a much more comprehensive example on
fine-tuning a plot using backend-specific commands. That file shows
how this can be done in almost all the supported backends.</p>
<p><em>Working with Axis and Figure Objects.</em> Easyviz supports the concept of Axis objects, as in Matlab.
The Axis object represents a set of axes, with curves drawn in the
associated coordinate system. A figure is the complete physical plot.
One may have several axes in one figure, each axis representing a subplot.
One may also have several figures, represented by different
windows on the screen or separate hardcopies.</p>
<p>Users with Matlab experience may prefer to set axis
labels, ranges, and the title using an Axis object instead of
providing the information in separate commands or as part of a <tt class="docutils literal"><span class="pre">plot</span></tt>
command. The <tt class="docutils literal"><span class="pre">gca</span></tt> (get current axis) command returns an <tt class="docutils literal"><span class="pre">Axis</span></tt>
object, whose <tt class="docutils literal"><span class="pre">set</span></tt> method can be used to set axis properties:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="s">&#39;r-&#39;</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="s">&#39;bo&#39;</span><span class="p">,</span>
     <span class="n">legend</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;t^2*exp(-t^2)&#39;</span><span class="p">,</span> <span class="s">&#39;t^4*exp(-t^2)&#39;</span><span class="p">),</span>
     <span class="n">hardcopy</span><span class="o">=</span><span class="s">&#39;tmp2.eps&#39;</span><span class="p">)</span>

<span class="n">ax</span> <span class="o">=</span> <span class="n">gca</span><span class="p">()</span>   <span class="c"># get current Axis object</span>
<span class="n">ax</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;y&#39;</span><span class="p">,</span>
        <span class="n">axis</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">],</span>
        <span class="n">title</span><span class="o">=</span><span class="s">&#39;Plotting two curves in the same plot&#39;</span><span class="p">)</span>
<span class="n">show</span><span class="p">()</span>  <span class="c"># show the plot again after ax.setp actions</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">figure()</span></tt> call makes a new figure, i.e., a
new window with curve plots. Figures are numbered as 1, 2, and so on.
The command <tt class="docutils literal"><span class="pre">figure(3)</span></tt> sets the current figure object to figure number
3.</p>
<p>Suppose we want to plot our <tt class="docutils literal"><span class="pre">y1</span></tt> and <tt class="docutils literal"><span class="pre">y2</span></tt> data in two separate windows.
We need in this case to work with two <tt class="docutils literal"><span class="pre">Figure</span></tt> objects:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="s">&#39;r-&#39;</span><span class="p">,</span> <span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;y&#39;</span><span class="p">,</span>
     <span class="n">axis</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">])</span>

<span class="n">figure</span><span class="p">()</span>  <span class="c"># new figure</span>

<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="s">&#39;bo&#39;</span><span class="p">,</span> <span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;y&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>We may now go back to the first figure (with the <tt class="docutils literal"><span class="pre">y1</span></tt> data) and
set a title and legends in this plot, show the plot, and make a PostScript
version of the plot:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">figure</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>  <span class="c"># go back to first figure</span>
<span class="n">title</span><span class="p">(</span><span class="s">&#39;One curve&#39;</span><span class="p">)</span>
<span class="n">legend</span><span class="p">(</span><span class="s">&#39;t^2*exp(-t^2)&#39;</span><span class="p">)</span>
<span class="n">show</span><span class="p">()</span>
<span class="n">hardcopy</span><span class="p">(</span><span class="s">&#39;tmp2_1.eps&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>We can also adjust figure 2:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">figure</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>  <span class="c"># go to second figure</span>
<span class="n">title</span><span class="p">(</span><span class="s">&#39;Another curve&#39;</span><span class="p">)</span>
<span class="n">hardcopy</span><span class="p">(</span><span class="s">&#39;tmp2_2.eps&#39;</span><span class="p">)</span>
<span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>The current <tt class="docutils literal"><span class="pre">Figure</span></tt> object is reached by <tt class="docutils literal"><span class="pre">gcf</span></tt> (get current figure),
and the <tt class="docutils literal"><span class="pre">dump</span></tt> method dumps the internal parameters in the <tt class="docutils literal"><span class="pre">Figure</span></tt>
object:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">fig</span> <span class="o">=</span> <span class="n">gcf</span><span class="p">();</span> <span class="k">print</span> <span class="n">fig</span><span class="o">.</span><span class="n">dump</span><span class="p">()</span>
</pre></div>
</div>
<p>These parameters may be of interest for troubleshooting when Easyviz
does not produce what you expect.</p>
<p>Let us then make a third figure with two plots, or more precisely, two
axes: one with <tt class="docutils literal"><span class="pre">y1</span></tt> data and one with <tt class="docutils literal"><span class="pre">y2</span></tt> data.
Easyviz has a command <tt class="docutils literal"><span class="pre">subplot(r,c,a)</span></tt> for creating <tt class="docutils literal"><span class="pre">r</span></tt>
rows and <tt class="docutils literal"><span class="pre">c</span></tt> columns and set the current axis to axis number <tt class="docutils literal"><span class="pre">a</span></tt>.
In the present case <tt class="docutils literal"><span class="pre">subplot(2,1,1)</span></tt> sets the current axis to
the first set of axis in a &#8220;table&#8221; with two rows and one column.
Here is the code for this third figure:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">figure</span><span class="p">()</span>  <span class="c"># new, third figure</span>
<span class="c"># plot y1 and y2 as two axis in the same figure:</span>
<span class="n">subplot</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;y&#39;</span><span class="p">)</span>
<span class="n">subplot</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;y&#39;</span><span class="p">)</span>
<span class="n">title</span><span class="p">(</span><span class="s">&#39;A figure with two plots&#39;</span><span class="p">)</span>
<span class="n">show</span><span class="p">()</span>
<span class="n">hardcopy</span><span class="p">(</span><span class="s">&#39;tmp2_3.eps&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>If we need to place an axis at an arbitrary position in the figure, we
must use the command</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">ax</span> <span class="o">=</span> <span class="n">axes</span><span class="p">(</span><span class="n">viewport</span><span class="o">=</span><span class="p">[</span><span class="n">left</span><span class="p">,</span> <span class="n">bottom</span><span class="p">,</span> <span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">])</span>
</pre></div>
</div>
<p>The four parameteres <tt class="docutils literal"><span class="pre">left</span></tt>, <tt class="docutils literal"><span class="pre">bottom</span></tt>, <tt class="docutils literal"><span class="pre">width</span></tt>, <tt class="docutils literal"><span class="pre">height</span></tt>
are location values between 0 and 1 ((0,0) is the lower-left corner
and (1,1) is the upper-right corner). However, this might be a bit
different in the different backends (see the documentation for the
backend in question).</p>
</div>
</div>
<div class="section" id="visualization-of-scalar-fields">
<h1>Visualization of Scalar Fields<a class="headerlink" href="#visualization-of-scalar-fields" title="Permalink to this headline">¶</a></h1>
<p>A scalar field is a function from space or space-time to a real value.
This real value typically reflects a scalar physical parameter at every
point in space (or in space and time). One example is temperature,
which is a scalar quantity defined everywhere in space and time.  In a
visualization context, we work with discrete scalar fields that are
defined on a grid. Each point in the grid is then associated with a
scalar value.</p>
<p>There are several ways to visualize a scalar field in Easyviz. Both
two- and three-dimensional scalar fields are supported. In two
dimensions (2D) we can create elevated surface plots, contour plots,
and pseudocolor plots, while in three dimensions (3D) we can create
isosurface plots, volumetric slice plots, and contour slice plots.</p>
<div class="section" id="elevated-surface-plots">
<h2>Elevated Surface Plots<a class="headerlink" href="#elevated-surface-plots" title="Permalink to this headline">¶</a></h2>
<p>To create elevated surface plots we can use either the <tt class="docutils literal"><span class="pre">surf</span></tt> or the
<tt class="docutils literal"><span class="pre">mesh</span></tt> command. Both commands have the same syntax, but the <tt class="docutils literal"><span class="pre">mesh</span></tt>
command creates a wireframe mesh while the <tt class="docutils literal"><span class="pre">surf</span></tt> command creates a
solid colored surface.</p>
<p>Our examples will make use of the scalar field
<img class="math" src="_images/math/bc462d8fa9f95c52d23845d3c0f68a269980d795.png" alt="f(x,y) = \sin r"/>,
where <img class="math" src="_images/math/b55ca7a0aa88ab7d58f4fc035317fdac39b17861.png" alt="r"/> is the distance in the plane from the origin, i.e.,
<img class="math" src="_images/math/ccb0e45e7f19d4ff5157544736c7e788ea6c699c.png" alt="r=\sqrt{x^2+y^2}"/>.
The <img class="math" src="_images/math/26eeb5258ca5099acf8fe96b2a1049c48c89a5e6.png" alt="x"/> and <img class="math" src="_images/math/092e364e1d9d19ad5fffb0b46ef4cc7f2da02c1c.png" alt="y"/> values in our 2D domain lie between -5 and 5.</p>
<p>The example first creates the necessary data arrays for 2D scalar
field plotting: the coordinates in each direction, extensions of these
arrays to form a <em>ndgrid</em>, and the function values. The latter array
is computed in a vectorized operation which requires the extended
coordinate arrays from the <tt class="docutils literal"><span class="pre">ndgrid</span></tt> function.  The <tt class="docutils literal"><span class="pre">mesh</span></tt> command
can then produce the plot with a syntax that mirrors the simplicity of
the <tt class="docutils literal"><span class="pre">plot</span></tt> command for curves:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">x</span> <span class="o">=</span> <span class="n">y</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">21</span><span class="p">)</span>
<span class="n">xv</span><span class="p">,</span> <span class="n">yv</span> <span class="o">=</span> <span class="n">ndgrid</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="n">values</span> <span class="o">=</span> <span class="n">sin</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">xv</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">yv</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">mesh</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">mesh</span></tt> command returns a reference to a new <tt class="docutils literal"><span class="pre">Surface</span></tt> object, here
stored in a variable h. This reference can be used to set or get
properties in the object at a later stage if needed.  The resulting
plot can be seen in Figure <a class="reference internal" href="#fig-mesh-ex1"><em>Result of the mesh command for plotting a 2D scalar field (Gnuplot backend).</em></a>.</p>
<p>We remark that the computations in the previous example are vectorized.
The corresponding scalar computations using a double loop read</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">values</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">size</span><span class="p">,</span> <span class="n">y</span><span class="o">.</span><span class="n">size</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">size</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">y</span><span class="o">.</span><span class="n">size</span><span class="p">):</span>
        <span class="n">values</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">sin</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
</pre></div>
</div>
<p>However, for the <tt class="docutils literal"><span class="pre">mesh</span></tt> command to work, we need the vectorized
extensions <tt class="docutils literal"><span class="pre">xv</span></tt> and <tt class="docutils literal"><span class="pre">yv</span></tt> of <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt>.</p>
<div class="figure" id="fig-mesh-ex1">
<img alt="_images/mesh_ex1.png" src="_images/mesh_ex1.png" />
<p class="caption">Result of the mesh command for plotting a 2D scalar field (Gnuplot backend).</p>
</div>
<p>The <tt class="docutils literal"><span class="pre">surf</span></tt> command employs the same syntax, but results in a different
plot (see Figure <a class="reference internal" href="#fig-surf-ex1"><em>Result of the surf command (Gnuplot backend).</em></a>):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">surf</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
</pre></div>
</div>
<div class="figure" id="fig-surf-ex1">
<img alt="_images/surf_ex1.png" src="_images/surf_ex1.png" />
<p class="caption">Result of the surf command (Gnuplot backend).</p>
</div>
<p>The <tt class="docutils literal"><span class="pre">surf</span></tt> command offers many possibilities to adjust the resulting plot:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">setp</span><span class="p">(</span><span class="n">interactive</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="n">surf</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
<span class="n">shading</span><span class="p">(</span><span class="s">&#39;flat&#39;</span><span class="p">)</span>
<span class="n">colorbar</span><span class="p">()</span>
<span class="n">colormap</span><span class="p">(</span><span class="n">hot</span><span class="p">())</span>
<span class="n">axis</span><span class="p">([</span><span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="o">-</span><span class="mf">1.5</span><span class="p">,</span><span class="mf">1.5</span><span class="p">])</span>
<span class="n">view</span><span class="p">(</span><span class="mi">35</span><span class="p">,</span><span class="mi">45</span><span class="p">)</span>
<span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>Here we have specified a flat shading model, added a color bar, changed
the color map to <tt class="docutils literal"><span class="pre">hot</span></tt>, set some suitable axis values, and changed the
view point (the view takes two arguments: the azimuthal rotation and
the elevation, both given in degrees).
The same plot can also be accomplished with one single, compound
statement (just as Easyviz offers for the <tt class="docutils literal"><span class="pre">plot</span></tt> command):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">surf</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span>
     <span class="n">shading</span><span class="o">=</span><span class="s">&#39;flat&#39;</span><span class="p">,</span>
     <span class="n">colorbar</span><span class="o">=</span><span class="s">&#39;on&#39;</span><span class="p">,</span>
     <span class="n">colormap</span><span class="o">=</span><span class="n">hot</span><span class="p">(),</span>
     <span class="n">axis</span><span class="o">=</span><span class="p">[</span><span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="o">-</span><span class="mf">1.5</span><span class="p">,</span><span class="mf">1.5</span><span class="p">],</span>
     <span class="n">view</span><span class="o">=</span><span class="p">[</span><span class="mi">35</span><span class="p">,</span><span class="mi">45</span><span class="p">])</span>
</pre></div>
</div>
<p>Figure <a class="reference internal" href="#fig-surf-ex2"><em>Result of an extended surf command (Gnuplot backend).</em></a> displays the result.</p>
<div class="figure" id="fig-surf-ex2">
<img alt="_images/surf_ex2.png" src="_images/surf_ex2.png" />
<p class="caption">Result of an extended surf command (Gnuplot backend).</p>
</div>
</div>
<div class="section" id="contour-plots">
<h2>Contour Plots<a class="headerlink" href="#contour-plots" title="Permalink to this headline">¶</a></h2>
<p>A contour plot is another useful technique for visualizing scalar
fields. The primary examples on contour plots from everyday life is
the level curves on geographical maps, reflecting the height of the
terrain. Mathematically, a contour line, also called an isoline, is
defined as the implicit curve <img class="math" src="_images/math/9a744c62d49e0ce62a0f8e5070934a96e956f39c.png" alt="f(x,y)=c"/>. The contour levels <img class="math" src="_images/math/3372c1cb6d68cf97c2d231acc0b47b95a9ed04cc.png" alt="c"/> are
normally uniformly distributed between the extreme values of the
function <img class="math" src="_images/math/bb2c93730dbb48558bb3c4738c956c4e8f816437.png" alt="f"/> (this is the case in a map: the height difference between
two contour lines is constant), but in scientific visualization it is
sometimes useful to use a few carefully selected <img class="math" src="_images/math/3372c1cb6d68cf97c2d231acc0b47b95a9ed04cc.png" alt="c"/> values to
illustrate particular features of a scalar field.</p>
<p>In Easyviz, there are several commands for creating different kinds of
contour plots:</p>
<blockquote>
<ul>
<li><p class="first"><tt class="docutils literal"><span class="pre">contour</span></tt>: Draw a standard contour plot, i.e., lines in the plane.</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">contourf</span></tt>: Draw a filled 2D contour plot, where the space between
the contour lines is filled with colors.</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">contour3</span></tt>: Same as <tt class="docutils literal"><span class="pre">contour</span></tt>, but the curves are drawn at their
corresponding height levels in 3D space.</p>
</li>
<li><dl class="first docutils">
<dt><tt class="docutils literal"><span class="pre">meshc</span></tt>: Works in the same way as <tt class="docutils literal"><span class="pre">mesh</span></tt> except that a</dt>
<dd><p class="first last">contour plot is drawn in the plane beneath the mesh.</p>
</dd>
</dl>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">surfc</span></tt>: Same as <tt class="docutils literal"><span class="pre">meshc</span></tt> except that a solid surface is
drawn instead of a wireframe mesh.</p>
</li>
</ul>
</blockquote>
<p>We start with illustrating the plain <tt class="docutils literal"><span class="pre">contour</span></tt> command, assuming that
we already have computed the <tt class="docutils literal"><span class="pre">xv</span></tt>, <tt class="docutils literal"><span class="pre">yv</span></tt>, and <tt class="docutils literal"><span class="pre">values</span></tt>
arrays as shown in our first example on scalar field plotting.
The basic syntax follows that of <tt class="docutils literal"><span class="pre">mesh</span></tt> and <tt class="docutils literal"><span class="pre">surf</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">contour</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
</pre></div>
</div>
<p>By default, five uniformly spaced contour level curves are drawn, see
Figure <a class="reference internal" href="#fig-contour-ex1"><em>Result of the simplest possible contour command (Gnuplot backend).</em></a>.</p>
<div class="figure" id="fig-contour-ex1">
<img alt="_images/contour_ex1.png" src="_images/contour_ex1.png" />
<p class="caption">Result of the simplest possible contour command (Gnuplot backend).</p>
</div>
<p>The number of levels in a contour plot can be specified with an additional
argument:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">n</span> <span class="o">=</span> <span class="mi">15</span>   <span class="c"># number of desired contour levels</span>
<span class="n">contour</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
</pre></div>
</div>
<p>The result can be seen in Figure <a class="reference internal" href="#fig-contour-ex2"><em>A contour plot with 15 contour levels (Gnuplot backend).</em></a>.</p>
<div class="figure" id="fig-contour-ex2">
<img alt="_images/contour_ex2.png" src="_images/contour_ex2.png" />
<p class="caption">A contour plot with 15 contour levels (Gnuplot backend).</p>
</div>
<p>Sometimes one wants contour levels that are not equidistant or not
distributed throughout the range of the scalar field. Individual
contour levels to be drawn can easily be specified as a list:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">levels</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">]</span>
<span class="n">contour</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="n">levels</span><span class="p">,</span> <span class="n">clabels</span><span class="o">=</span><span class="s">&#39;on&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Now, the <tt class="docutils literal"><span class="pre">levels</span></tt> list specify the values of the contour levels, and
the <tt class="docutils literal"><span class="pre">clabel</span></tt> keyword allows labeling of the level values in the plot.
Figure <a class="reference internal" href="#fig-contour-ex3"><em>Four individually specified contour levels (Gnuplot backend).</em></a> shows the result. We remark that the
Gnuplot backend colors the contour lines and places the contour values
and corresponding colors beside the plot. Figures that are reproduced
in black and white only can then be hard to analyze. Other backends
may draw the contour lines in black and annotate each line with the
corresponding contour level value.  Such plots are better suited for
being displayed in black and white.</p>
<div class="figure" id="fig-contour-ex3">
<img alt="_images/contour_ex3.png" src="_images/contour_ex3.png" />
<p class="caption">Four individually specified contour levels (Gnuplot backend).</p>
</div>
<p>The <tt class="docutils literal"><span class="pre">contourf</span></tt> command,</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">contourf</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
</pre></div>
</div>
<p>gives a filled contour plot as shown in Figure <a class="reference internal" href="#fig-contourf-ex1"><em>Filled contour plot created by the contourf command (VTK backend).</em></a>.
Only the Matplotlib and VTK backends currently supports filled
contour plots.</p>
<div class="figure" id="fig-contourf-ex1">
<img alt="_images/contourf_ex1.png" src="_images/contourf_ex1.png" />
<p class="caption">Filled contour plot created by the contourf command (VTK backend).</p>
</div>
<p>The contour lines can be &#8220;lifted up&#8221; in 3D space, as shown in Figure
<a class="reference internal" href="#fig-contour3-ex1"><em>Example on the contour3 command for elevated contour levels (Gnuplot backend).</em></a>, using the <tt class="docutils literal"><span class="pre">contour3</span></tt> command:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">contour3</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="mi">15</span><span class="p">)</span>
</pre></div>
</div>
<div class="figure" id="fig-contour3-ex1">
<img alt="_images/contour3_ex1.png" src="_images/contour3_ex1.png" />
<p class="caption">Example on the contour3 command for elevated contour levels (Gnuplot backend).</p>
</div>
<p>Finally, we show a simple example illustrating the <tt class="docutils literal"><span class="pre">meshc</span></tt> and <tt class="docutils literal"><span class="pre">surfc</span></tt>
commands:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">meshc</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span>
      <span class="n">clevels</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span>
      <span class="n">colormap</span><span class="o">=</span><span class="n">hot</span><span class="p">(),</span>
      <span class="n">grid</span><span class="o">=</span><span class="s">&#39;off&#39;</span><span class="p">)</span>
<span class="n">figure</span><span class="p">()</span>
<span class="n">surfc</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span>
      <span class="n">clevels</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span>
      <span class="n">colormap</span><span class="o">=</span><span class="n">hsv</span><span class="p">(),</span>
      <span class="n">grid</span><span class="o">=</span><span class="s">&#39;off&#39;</span><span class="p">,</span>
      <span class="n">view</span><span class="o">=</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span><span class="mi">40</span><span class="p">))</span>
</pre></div>
</div>
<p>The resulting plots are displayed in Figures <a class="reference internal" href="#fig-meshc-ex1"><em>Wireframe mesh with contours at the bottom (Gnuplot backend).</em></a> and
<a class="reference internal" href="#fig-surfc-ex1"><em>Surface plot with contours (Gnuplot backend).</em></a>.</p>
<div class="figure" id="fig-meshc-ex1">
<img alt="_images/meshc_ex1.png" src="_images/meshc_ex1.png" />
<p class="caption">Wireframe mesh with contours at the bottom (Gnuplot backend).</p>
</div>
<div class="figure" id="fig-surfc-ex1">
<img alt="_images/surfc_ex1.png" src="_images/surfc_ex1.png" />
<p class="caption">Surface plot with contours (Gnuplot backend).</p>
</div>
</div>
<div class="section" id="pseudocolor-plots">
<h2>Pseudocolor Plots<a class="headerlink" href="#pseudocolor-plots" title="Permalink to this headline">¶</a></h2>
<p>Another way of visualizing a 2D scalar field in Easyviz is the
<tt class="docutils literal"><span class="pre">pcolor</span></tt> command. This command creates a pseudocolor plot, which is a
flat surface viewed from above. The simplest form of this command
follows the syntax of the other commands:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">pcolor</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
</pre></div>
</div>
<p>We can set the color shading in a pseudocolor plot either by giving
the <tt class="docutils literal"><span class="pre">shading</span></tt> keyword argument to <tt class="docutils literal"><span class="pre">pcolor</span></tt> or by calling the <tt class="docutils literal"><span class="pre">shading</span></tt>
command. The color shading is specified by a string that can be either
<tt class="docutils literal"><span class="pre">'faceted'</span></tt> (default), <tt class="docutils literal"><span class="pre">'flat'</span></tt>, or <tt class="docutils literal"><span class="pre">'interp'</span></tt> (interpolated). The Gnuplot and
Matplotlib backends support <tt class="docutils literal"><span class="pre">'faceted'</span></tt> and <tt class="docutils literal"><span class="pre">'flat'</span></tt> only, while the
VTK backend supports all of them.</p>
<div class="figure">
<img alt="_images/pcolor_ex1.png" src="_images/pcolor_ex1.png" />
<p class="caption">Pseudocolor plot (Gnuplot backend).</p>
</div>
</div>
<div class="section" id="isosurface-plots">
<h2>Isosurface Plots<a class="headerlink" href="#isosurface-plots" title="Permalink to this headline">¶</a></h2>
<p>For 3D scalar fields, isosurfaces or contour surfaces constitute the counterpart to contour
lines or isolines for 2D scalar fields. An isosurface connects points in
a scalar field with (approximately) the same scalar value and is
mathematically defined by the implicit equation <img class="math" src="_images/math/f36b61c48cb9a0dbc80e699524d8a20727e1ee46.png" alt="f(x,y,z)=c"/>. In Easyviz,
isosurfaces are created with the <tt class="docutils literal"><span class="pre">isosurface</span></tt> command. We will
demonstrate this command using 3D scalar field data from the <tt class="docutils literal"><span class="pre">flow</span></tt>
function. This function, also found in Matlab,
generates fluid flow data. Our first isosurface visualization example
then looks as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">v</span> <span class="o">=</span> <span class="n">flow</span><span class="p">()</span>  <span class="c"># generate fluid-flow data</span>
<span class="n">setp</span><span class="p">(</span><span class="n">interactive</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">isosurface</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">z</span><span class="p">,</span><span class="n">v</span><span class="p">,</span><span class="o">-</span><span class="mi">3</span><span class="p">)</span>
<span class="n">h</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="n">opacity</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
<span class="n">shading</span><span class="p">(</span><span class="s">&#39;interp&#39;</span><span class="p">)</span>
<span class="n">daspect</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span>
<span class="n">view</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="n">axis</span><span class="p">(</span><span class="s">&#39;tight&#39;</span><span class="p">)</span>
<span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>After creating some scalar volume data with the <tt class="docutils literal"><span class="pre">flow</span></tt> function, we
create an isosurface with the isovalue <img class="math" src="_images/math/0b31b51deaa1a9e903d120a02141556c3e70e348.png" alt="-3"/>. The isosurface is then
set a bit transparent (<tt class="docutils literal"><span class="pre">opacity=0.5</span></tt>) before we specify the shading
model and the view point. We also set the data aspect ratio to be
equal in all directions with the <tt class="docutils literal"><span class="pre">daspect</span></tt> command.  The resulting
plot is shown in Figure <a class="reference internal" href="#fig-isosurface1"><em>Isosurface plot (VTK backend).</em></a>. We remark that the
Gnuplot backend does not support 3D scalar fields and hence not
isosurfaces.</p>
<div class="figure" id="fig-isosurface1">
<img alt="_images/isosurface1.png" src="_images/isosurface1.png" />
<p class="caption">Isosurface plot (VTK backend).</p>
</div>
<p>Here is another example that demonstrates the <tt class="docutils literal"><span class="pre">isosurface</span></tt> command
(again using the <tt class="docutils literal"><span class="pre">flow</span></tt> function):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">v</span> <span class="o">=</span> <span class="n">flow</span><span class="p">()</span>
<span class="n">setp</span><span class="p">(</span><span class="n">interactive</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">isosurface</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">z</span><span class="p">,</span><span class="n">v</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="n">shading</span><span class="p">(</span><span class="s">&#39;interp&#39;</span><span class="p">)</span>
<span class="n">daspect</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">])</span>
<span class="n">view</span><span class="p">([</span><span class="o">-</span><span class="mi">65</span><span class="p">,</span><span class="mi">20</span><span class="p">])</span>
<span class="n">axis</span><span class="p">(</span><span class="s">&#39;tight&#39;</span><span class="p">)</span>
<span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>Figure <em class="xref std std-ref">fig:isosurface2</em> shows the resulting plot.</p>
<div class="figure">
<img alt="_images/isosurface2.png" src="_images/isosurface2.png" />
<p class="caption">Another isosurface plot (VTK backend). label:ref:<cite>fig:isosurface2</cite></p>
</div>
</div>
<div class="section" id="volumetric-slice-plot">
<h2>Volumetric Slice Plot<a class="headerlink" href="#volumetric-slice-plot" title="Permalink to this headline">¶</a></h2>
<p>Another way of visualizing scalar volume data is by using the <tt class="docutils literal"><span class="pre">slice_</span></tt>
command (since the name <tt class="docutils literal"><span class="pre">slice</span></tt> is already taken by a built-in
function in Python for array slicing, we have followed the standard
Python convention and added a trailing underscore to the name in
Easyviz - <tt class="docutils literal"><span class="pre">slice_</span></tt> is thus the counterpart to the Matlab function
<tt class="docutils literal"><span class="pre">slice</span></tt>.). This command draws orthogonal slice planes through a
given volumetric data set. Here is an example on how to use the
<tt class="docutils literal"><span class="pre">slice_</span></tt> command:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">ndgrid</span><span class="p">(</span><span class="n">seq</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="o">.</span><span class="mi">2</span><span class="p">),</span> <span class="n">seq</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="o">.</span><span class="mi">25</span><span class="p">),</span> <span class="n">seq</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="o">.</span><span class="mi">16</span><span class="p">),</span>
                   <span class="n">sparse</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">v</span> <span class="o">=</span> <span class="n">x</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="n">y</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="n">z</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="n">xslice</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mf">1.2</span><span class="p">,</span> <span class="o">.</span><span class="mi">8</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
<span class="n">yslice</span> <span class="o">=</span> <span class="mi">2</span>
<span class="n">zslice</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
<span class="n">slice_</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">xslice</span><span class="p">,</span> <span class="n">yslice</span><span class="p">,</span> <span class="n">zslice</span><span class="p">,</span>
       <span class="n">colormap</span><span class="o">=</span><span class="n">hsv</span><span class="p">(),</span> <span class="n">grid</span><span class="o">=</span><span class="s">&#39;off&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that we here use the SciTools function <tt class="docutils literal"><span class="pre">seq</span></tt> for specifying a
uniform partitioning of an interval - the <tt class="docutils literal"><span class="pre">linspace</span></tt> function from
<tt class="docutils literal"><span class="pre">numpy</span></tt> could equally well be used.  The first three arguments in the
<tt class="docutils literal"><span class="pre">slice_</span></tt> call are the grid points in the <img class="math" src="_images/math/26eeb5258ca5099acf8fe96b2a1049c48c89a5e6.png" alt="x"/>, <img class="math" src="_images/math/092e364e1d9d19ad5fffb0b46ef4cc7f2da02c1c.png" alt="y"/>, and <img class="math" src="_images/math/b13f21416d84e13708696f34dea81026cda583c9.png" alt="z"/>
directions. The fourth argument is the scalar field defined on-top of
the grid. The next three arguments defines either slice planes in the
three space directions or a surface plane (currently not working). In
this example we have created 6 slice planes: Three at the <img class="math" src="_images/math/26eeb5258ca5099acf8fe96b2a1049c48c89a5e6.png" alt="x"/> axis (at
<img class="math" src="_images/math/9ee52f91385e3e08732a08d23b09088ee670760f.png" alt="x=-1.2"/>, <img class="math" src="_images/math/baf6b2c5584a7023b57afe73e0a36b6f5a3fcad7.png" alt="x=0.8"/>, and <img class="math" src="_images/math/69271b422e022ea65ff1f288eddfcfa82afd8ab7.png" alt="x=2"/>), one at the <img class="math" src="_images/math/092e364e1d9d19ad5fffb0b46ef4cc7f2da02c1c.png" alt="y"/> axis (at <img class="math" src="_images/math/40ac4b6f5ab516ac6fe7132ed2fe7a1d77ca02dd.png" alt="y=2"/>), and two
at the <img class="math" src="_images/math/b13f21416d84e13708696f34dea81026cda583c9.png" alt="z"/> axis (at <img class="math" src="_images/math/470f01e54c49a9976bb32e37817453f24bfa8817.png" alt="z=-2"/> and <img class="math" src="_images/math/5510380da19a236624ef45908d2da469f892b03e.png" alt="z=0.0"/>). The result is presented in
Figure <a class="reference internal" href="#fig-slice1"><em>Slice plot where the  axis is sliced at -1.2, 0.8, and 2, the  axis is sliced at 2, and the  axis is sliced at -2 and 0.0 (VTK backend).</em></a>.</p>
<div class="figure" id="fig-slice1">
<img alt="_images/slice1.png" src="_images/slice1.png" />
<p class="caption">Slice plot where the <img class="math" src="_images/math/26eeb5258ca5099acf8fe96b2a1049c48c89a5e6.png" alt="x"/> axis is sliced at -1.2, 0.8, and 2, the <img class="math" src="_images/math/092e364e1d9d19ad5fffb0b46ef4cc7f2da02c1c.png" alt="y"/> axis is sliced at 2, and the <img class="math" src="_images/math/b13f21416d84e13708696f34dea81026cda583c9.png" alt="z"/> axis is sliced at -2 and 0.0 (VTK backend).</p>
</div>
<p><em>Contours in Slice Planes.</em> With the <tt class="docutils literal"><span class="pre">contourslice</span></tt> command we can create contour plots
in planes aligned with the coordinate axes. Here is an example
using 3D scalar field data from the <tt class="docutils literal"><span class="pre">flow</span></tt> function:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">v</span> <span class="o">=</span> <span class="n">flow</span><span class="p">()</span>
<span class="n">setp</span><span class="p">(</span><span class="n">interactive</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">contourslice</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">seq</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">9</span><span class="p">),</span> <span class="p">[],</span> <span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">8</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">10</span><span class="p">))</span>
<span class="n">axis</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="o">-</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="n">daspect</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">gca</span><span class="p">()</span>
<span class="n">ax</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="n">fgcolor</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">),</span> <span class="n">bgcolor</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">))</span>
<span class="n">box</span><span class="p">(</span><span class="s">&#39;on&#39;</span><span class="p">)</span>
<span class="n">view</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>The first four arguments given to <tt class="docutils literal"><span class="pre">contourslice</span></tt> in this example are
the extended coordinates of the grid (<tt class="docutils literal"><span class="pre">x</span></tt>, <tt class="docutils literal"><span class="pre">y</span></tt>, <tt class="docutils literal"><span class="pre">z</span></tt>) and the 3D scalar
field values in the volume (<tt class="docutils literal"><span class="pre">v</span></tt>). The next three arguments defines the
slice planes in which we want to draw contour lines. In this
particular example we have specified two contour plots in the planes
<img class="math" src="_images/math/2a9d69f16b8563779b74862c69101e431b313fae.png" alt="x=1,2,\dots,9"/>, none in <img class="math" src="_images/math/e041c5053df90af915d5b5c2aff1a51734a9ca49.png" alt="y=\hbox{const}"/> planes (empty
list) , and one contour plot in the plane <img class="math" src="_images/math/72079803c6fcdcfa95b6d7f383f6ad71f1eb631b.png" alt="z=0"/>. The last argument to
<tt class="docutils literal"><span class="pre">contourslice</span></tt> is optional, it can be either an integer specifying the
number of contour lines (the default is five) or, as in the current
example, a list specifying the level curves. Running the set of
commands results in the plot shown in Figure <a class="reference internal" href="#fig-contourslice1"><em>Contours in slice planes (VTK backend).</em></a>.</p>
<div class="figure" id="fig-contourslice1">
<img alt="_images/contourslice1.png" src="_images/contourslice1.png" />
<p class="caption">Contours in slice planes (VTK backend).</p>
</div>
<p>Here is another example where we draw contour slices from a
three-dimensional MRI data set:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">scipy.io</span>
<span class="n">mri</span> <span class="o">=</span> <span class="n">scipy</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">loadmat</span><span class="p">(</span><span class="s">&#39;mri_matlab_v6.mat&#39;</span><span class="p">)</span>
<span class="n">D</span> <span class="o">=</span> <span class="n">mri</span><span class="p">[</span><span class="s">&#39;D&#39;</span><span class="p">]</span>
<span class="n">image_num</span> <span class="o">=</span> <span class="mi">8</span>

<span class="c"># Displaying a 2D Contour Slice:</span>
<span class="n">contourslice</span><span class="p">(</span><span class="n">D</span><span class="p">,</span> <span class="p">[],</span> <span class="p">[],</span> <span class="n">image_num</span><span class="p">,</span> <span class="n">daspect</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="n">indexing</span><span class="o">=</span><span class="s">&#39;xy&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The MRI data set is loaded from the file <tt class="docutils literal"><span class="pre">mri_matlab_v6.mat</span></tt> with the
aid from the <tt class="docutils literal"><span class="pre">loadmat</span></tt> function available in the <tt class="docutils literal"><span class="pre">io</span></tt> module in the
SciPy package. We then create a 2D contour slice plot with one slice
in the plane <img class="math" src="_images/math/2be940191460cd30cc15596e01d6d7c52006dad3.png" alt="z=8"/>. Figure <a class="reference internal" href="#fig-contourslice3"><em>Contour slice plot of a 3D MRI data set (VTK backend).</em></a> displays the result.</p>
<div class="figure" id="fig-contourslice3">
<img alt="_images/contourslice3.png" src="_images/contourslice3.png" />
<p class="caption">Contour slice plot of a 3D MRI data set (VTK backend).</p>
</div>
</div>
</div>
<div class="section" id="visualization-of-vector-fields">
<h1>Visualization of Vector Fields<a class="headerlink" href="#visualization-of-vector-fields" title="Permalink to this headline">¶</a></h1>
<p>A vector field is a function from space or space-time to a vector
value, where the number of components in the vector corresponds to
the number of space dimensions. Primary examples on vector fields
are the gradient of a scalar field; or velocity, displacement, or
force in continuum physics.</p>
<p>In Easyviz, a vector field can be visualized either by a quiver
(arrow) plot or by various kinds of stream plots like stream lines,
stream ribbons, and stream tubes. Below we will look closer at each of
these visualization techniques.</p>
<div class="section" id="quiver-plots">
<h2>Quiver Plots<a class="headerlink" href="#quiver-plots" title="Permalink to this headline">¶</a></h2>
<p>The <tt class="docutils literal"><span class="pre">quiver</span></tt> and <tt class="docutils literal"><span class="pre">quiver3</span></tt> commands draw arrows to illustrate vector
values (length and direction) at discrete points.  As the names
indicate, <tt class="docutils literal"><span class="pre">quiver</span></tt> is for 2D vector fields in the plane and <tt class="docutils literal"><span class="pre">quiver3</span></tt>
plots vectors in 3D space.  The basic usage of the <tt class="docutils literal"><span class="pre">quiver</span></tt> command
goes as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">x</span> <span class="o">=</span> <span class="n">y</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">21</span><span class="p">)</span>
<span class="n">xv</span><span class="p">,</span> <span class="n">yv</span> <span class="o">=</span> <span class="n">ndgrid</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">sparse</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="n">values</span> <span class="o">=</span> <span class="n">sin</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">xv</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">yv</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
<span class="n">uv</span><span class="p">,</span> <span class="n">vv</span> <span class="o">=</span> <span class="n">gradient</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="n">quiver</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">uv</span><span class="p">,</span> <span class="n">vv</span><span class="p">)</span>
</pre></div>
</div>
<p>Our vector field in this example is simply the gradient of the scalar
field used to illustrate the commands for 2D scalar field plotting.
The <tt class="docutils literal"><span class="pre">gradient</span></tt> function computes the gradient using finite difference
approximations.  The result is a vector field with components <tt class="docutils literal"><span class="pre">uv</span></tt> and
<tt class="docutils literal"><span class="pre">vv</span></tt> in the <img class="math" src="_images/math/26eeb5258ca5099acf8fe96b2a1049c48c89a5e6.png" alt="x"/> and <img class="math" src="_images/math/092e364e1d9d19ad5fffb0b46ef4cc7f2da02c1c.png" alt="y"/> directions, respectively.  The grid points and
the vector components are passed as arguments to <tt class="docutils literal"><span class="pre">quiver</span></tt>, which in
turn produces the plot in Figure <a class="reference internal" href="#fig-quiver-ex1"><em>Velocity vector plot (Gnuplot backend).</em></a>.</p>
<div class="figure" id="fig-quiver-ex1">
<img alt="_images/quiver_ex1.png" src="_images/quiver_ex1.png" />
<p class="caption">Velocity vector plot (Gnuplot backend).</p>
</div>
<p>The arrows in a quiver plot are automatically scaled to fit within the
grid. If we want to control the length of the arrows, we can pass an
additional argument to scale the default lengths:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">scale</span> <span class="o">=</span> <span class="mi">2</span>
<span class="n">quiver</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">uv</span><span class="p">,</span> <span class="n">vv</span><span class="p">,</span> <span class="n">scale</span><span class="p">)</span>
</pre></div>
</div>
<p>This value of <tt class="docutils literal"><span class="pre">scale</span></tt> will thus stretch the vectors to their double length.
To turn off the automatic scaling, we can set the scale value to zero.</p>
<p>Quiver plots are often used in combination with other plotting
commands such as pseudocolor plots or contour plots, since this may
help to get a better perception of a given set of data. Here is an
example demonstrating this principle for a simple scalar field, where
we plot the field values as colors and add vectors to illustrate the
associated gradient field:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span> <span class="o">=</span> <span class="n">ndgrid</span><span class="p">(</span><span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">101</span><span class="p">),</span> <span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">101</span><span class="p">))</span>
<span class="n">values</span> <span class="o">=</span> <span class="n">sin</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">xv</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">yv</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
<span class="n">pcolor</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="n">shading</span><span class="o">=</span><span class="s">&#39;interp&#39;</span><span class="p">)</span>

<span class="c"># create a coarser grid for the gradient field:</span>
<span class="n">xv</span><span class="p">,</span> <span class="n">yv</span> <span class="o">=</span> <span class="n">ndgrid</span><span class="p">(</span><span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">21</span><span class="p">),</span> <span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">21</span><span class="p">))</span>
<span class="n">values</span> <span class="o">=</span> <span class="n">sin</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">xv</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">yv</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
<span class="n">uv</span><span class="p">,</span> <span class="n">vv</span> <span class="o">=</span> <span class="n">gradient</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="n">hold</span><span class="p">(</span><span class="s">&#39;on&#39;</span><span class="p">)</span>
<span class="n">quiver</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">uv</span><span class="p">,</span> <span class="n">vv</span><span class="p">,</span> <span class="s">&#39;filled&#39;</span><span class="p">,</span> <span class="s">&#39;k&#39;</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="p">[</span><span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="mi">6</span><span class="p">])</span>
<span class="n">figure</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="n">contour</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="mi">15</span><span class="p">)</span>
<span class="n">hold</span><span class="p">(</span><span class="s">&#39;on&#39;</span><span class="p">)</span>
<span class="n">quiver</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">uv</span><span class="p">,</span> <span class="n">vv</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="p">[</span><span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="mi">6</span><span class="p">])</span>
</pre></div>
</div>
<p>The resulting plots can be seen in Figure <a class="reference internal" href="#fig-quiver-ex2"><em>Combined quiver and pseudocolor plot (VTK backend).</em></a> and
<a class="reference internal" href="#fig-quiver-ex3"><em>Combined quiver and pseudocolor plot (VTK backend).</em></a>.</p>
<div class="figure" id="fig-quiver-ex2">
<img alt="_images/quiver_ex2.png" src="_images/quiver_ex2.png" />
<p class="caption">Combined quiver and pseudocolor plot (VTK backend).</p>
</div>
<div class="figure" id="fig-quiver-ex3">
<img alt="_images/quiver_ex3.png" src="_images/quiver_ex3.png" />
<p class="caption">Combined quiver and pseudocolor plot (VTK backend).</p>
</div>
<p>Visualization of 3D vector fields by arrows at grid points can be done
with the <tt class="docutils literal"><span class="pre">quiver3</span></tt> command. At the time of this writing, only the VTK
backend supports 3D quiver plots. A simple example of plotting the
&#8220;radius vector field&#8221; <img class="math" src="_images/math/f470ad5c7e6d92ed39da03ef8b1481a7de082b0d.png" alt="\vec v = (x,y,z)"/> is given next:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">x</span> <span class="o">=</span> <span class="n">y</span> <span class="o">=</span> <span class="n">z</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">)</span>
<span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">zv</span> <span class="o">=</span> <span class="n">ndgrid</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">sparse</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="n">uv</span> <span class="o">=</span> <span class="n">xv</span>
<span class="n">vv</span> <span class="o">=</span> <span class="n">yv</span>
<span class="n">wv</span> <span class="o">=</span> <span class="n">zv</span>
<span class="n">quiver3</span><span class="p">(</span><span class="n">xv</span><span class="p">,</span> <span class="n">yv</span><span class="p">,</span> <span class="n">zv</span><span class="p">,</span> <span class="n">uv</span><span class="p">,</span> <span class="n">vv</span><span class="p">,</span> <span class="n">wv</span><span class="p">,</span> <span class="s">&#39;filled&#39;</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="p">[</span><span class="o">-</span><span class="mi">7</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="o">-</span><span class="mi">7</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="o">-</span><span class="mi">7</span><span class="p">,</span><span class="mi">7</span><span class="p">])</span>
</pre></div>
</div>
<p>The strings <tt class="docutils literal"><span class="pre">'filled'</span></tt> and <tt class="docutils literal"><span class="pre">'r'</span></tt> are optional and makes the arrows
become filled
and red, respectively. The resulting plot is presented in Figure
<a class="reference internal" href="#fig-quiver3-ex1"><em>3D quiver plot (VTK backend).</em></a>.</p>
<div class="figure" id="fig-quiver3-ex1">
<img alt="_images/quiver3_ex1.png" src="_images/quiver3_ex1.png" />
<p class="caption">3D quiver plot (VTK backend).</p>
</div>
</div>
<div class="section" id="stream-plots">
<h2>Stream Plots<a class="headerlink" href="#stream-plots" title="Permalink to this headline">¶</a></h2>
<p>Stream plots constitute an alternative to arrow plots for visualizing
vector fields.  The stream plot commands currently available in
Easyviz are <tt class="docutils literal"><span class="pre">streamline</span></tt>, <tt class="docutils literal"><span class="pre">streamtube</span></tt>, and <tt class="docutils literal"><span class="pre">streamribbon</span></tt>.  Stream
lines are lines aligned with the vector field, i.e., the vectors are
tangents to the streamlines. Stream tubes are similar, but now the
surfaces of thin tubes are aligned with the vectors.  Stream ribbons
are also similar: thin sheets are aligned with the vectors. The latter
type of visualization is also known as stream or flow sheets.  In the
near future, Matlab commands such as <tt class="docutils literal"><span class="pre">streamslice</span></tt> and
<tt class="docutils literal"><span class="pre">streamparticles</span></tt> might also be implemented.</p>
<p>We start with an example on how to use the <tt class="docutils literal"><span class="pre">streamline</span></tt> command. In
this example (and in the following examples) we will use the <tt class="docutils literal"><span class="pre">wind</span></tt>
data set that is included with Matlab. This data set represents air
currents over a region of North America and is suitable for testing
the different stream plot commands. The following commands will load
the <tt class="docutils literal"><span class="pre">wind</span></tt> data set and then draw some stream lines from it:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">scipy.io</span>  <span class="c"># needed to load binary .mat-files</span>

<span class="c"># load the wind data set and create variables:</span>
<span class="n">wind</span> <span class="o">=</span> <span class="n">scipy</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">loadmat</span><span class="p">(</span><span class="s">&#39;wind.mat&#39;</span><span class="p">)</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">wind</span><span class="p">[</span><span class="s">&#39;x&#39;</span><span class="p">]</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">wind</span><span class="p">[</span><span class="s">&#39;y&#39;</span><span class="p">]</span>
<span class="n">z</span> <span class="o">=</span> <span class="n">wind</span><span class="p">[</span><span class="s">&#39;z&#39;</span><span class="p">]</span>
<span class="n">u</span> <span class="o">=</span> <span class="n">wind</span><span class="p">[</span><span class="s">&#39;u&#39;</span><span class="p">]</span>
<span class="n">v</span> <span class="o">=</span> <span class="n">wind</span><span class="p">[</span><span class="s">&#39;v&#39;</span><span class="p">]</span>
<span class="n">w</span> <span class="o">=</span> <span class="n">wind</span><span class="p">[</span><span class="s">&#39;w&#39;</span><span class="p">]</span>

<span class="c"># create starting points for the stream lines:</span>
<span class="n">sx</span><span class="p">,</span> <span class="n">sy</span><span class="p">,</span> <span class="n">sz</span> <span class="o">=</span> <span class="n">ndgrid</span><span class="p">([</span><span class="mi">80</span><span class="p">]</span><span class="o">*</span><span class="mi">4</span><span class="p">,</span> <span class="n">seq</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><span class="mi">50</span><span class="p">,</span><span class="mi">10</span><span class="p">),</span> <span class="n">seq</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">15</span><span class="p">,</span><span class="mi">5</span><span class="p">),</span>
                    <span class="n">sparse</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

<span class="c"># draw stream lines:</span>
<span class="n">streamline</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">w</span><span class="p">,</span> <span class="n">sx</span><span class="p">,</span> <span class="n">sy</span><span class="p">,</span> <span class="n">sz</span><span class="p">,</span>
           <span class="n">view</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="p">[</span><span class="mi">60</span><span class="p">,</span><span class="mi">140</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">60</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">20</span><span class="p">])</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">wind</span></tt> data set is stored in a binary <cite>.mat</cite>-file called
<tt class="docutils literal"><span class="pre">wind.mat</span></tt>. To load the data in this file into Python, we can use the
<tt class="docutils literal"><span class="pre">loadmat</span></tt> function which is available through the <tt class="docutils literal"><span class="pre">io</span></tt> module in
SciPy. Using the <tt class="docutils literal"><span class="pre">loadmat</span></tt> function on the <cite>wind.mat</cite>-file returns a
Python dictionary (called <tt class="docutils literal"><span class="pre">wind</span></tt> in the current example) containing the NumPy
arrays <tt class="docutils literal"><span class="pre">x</span></tt>, <tt class="docutils literal"><span class="pre">y</span></tt>, <tt class="docutils literal"><span class="pre">z</span></tt>, <tt class="docutils literal"><span class="pre">u</span></tt>, <tt class="docutils literal"><span class="pre">v</span></tt>, and <tt class="docutils literal"><span class="pre">w</span></tt>. The arrays <tt class="docutils literal"><span class="pre">u</span></tt>, <tt class="docutils literal"><span class="pre">v</span></tt>, and <tt class="docutils literal"><span class="pre">w</span></tt>
are the 3D vector data, while the arrays <tt class="docutils literal"><span class="pre">x</span></tt>, <tt class="docutils literal"><span class="pre">y</span></tt>, and <tt class="docutils literal"><span class="pre">z</span></tt> defines the
(3D extended) coordinates for the associated grid. The data arrays in
the dictionary <tt class="docutils literal"><span class="pre">wind</span></tt> are then stored in seperate variables for easier
access later.</p>
<p>Before we call the <tt class="docutils literal"><span class="pre">streamline</span></tt> command we must set up some starting
point coordinates for the stream lines. In this example, we have used
the <tt class="docutils literal"><span class="pre">ndgrid</span></tt> command to define the starting points with the line:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">sx</span><span class="p">,</span> <span class="n">sy</span><span class="p">,</span> <span class="n">sz</span> <span class="o">=</span> <span class="n">ndgrid</span><span class="p">([</span><span class="mi">80</span><span class="p">]</span><span class="o">*</span><span class="mi">4</span><span class="p">,</span> <span class="n">seq</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><span class="mi">50</span><span class="p">,</span><span class="mi">10</span><span class="p">),</span> <span class="n">seq</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">15</span><span class="p">,</span><span class="mi">5</span><span class="p">))</span>
</pre></div>
</div>
<p>This command defines starting points which all lie on <img class="math" src="_images/math/809d1f651ebe2560380b4047858d9087cb615073.png" alt="x=80"/>,
<img class="math" src="_images/math/0656ef5aaccdfe250f785474132685a62a88e168.png" alt="y=20,30,40,50"/>, and <img class="math" src="_images/math/aeb1c87941b336e9d1c9516922fe94d69d573db4.png" alt="z=0,5,10,15"/>. We now have all the data we need
for calling the <tt class="docutils literal"><span class="pre">streamline</span></tt> command. The first six arguments to the
<tt class="docutils literal"><span class="pre">streamline</span></tt> command are the grid coordinates <tt class="docutils literal"><span class="pre">(x,y,z)</span></tt> and the 3D
vector data <tt class="docutils literal"><span class="pre">(u,v,w)</span></tt>, while the next three arguments are the starting
points which we defined with the <tt class="docutils literal"><span class="pre">ndgrid</span></tt> command above. The
resulting plot is presented in Figure <a class="reference internal" href="#fig-streamline-ex1"><em>Stream line plot (Vtk backend).</em></a>.</p>
<div class="figure" id="fig-streamline-ex1">
<img alt="_images/streamline_ex1.png" src="_images/streamline_ex1.png" />
<p class="caption">Stream line plot (Vtk backend).</p>
</div>
<p>The next example demonstrates the <tt class="docutils literal"><span class="pre">streamtube</span></tt> command applied to the
same <tt class="docutils literal"><span class="pre">wind</span></tt> data set:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">streamtube</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">w</span><span class="p">,</span> <span class="n">sx</span><span class="p">,</span> <span class="n">sy</span><span class="p">,</span> <span class="n">sz</span><span class="p">,</span>
           <span class="n">daspect</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span>
           <span class="n">view</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
           <span class="n">axis</span><span class="o">=</span><span class="s">&#39;tight&#39;</span><span class="p">,</span>
           <span class="n">shading</span><span class="o">=</span><span class="s">&#39;interp&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The arrays <tt class="docutils literal"><span class="pre">sx</span></tt>, <tt class="docutils literal"><span class="pre">sy</span></tt>, and <tt class="docutils literal"><span class="pre">sz</span></tt> are the same as in the previous
example and defines the starting positions for the center lines of the
tubes. The resulting plot is presented in Figure
<a class="reference internal" href="#fig-streamtube-ex1"><em>Stream tubes (Vtk backend).</em></a>.</p>
<div class="figure" id="fig-streamtube-ex1">
<img alt="_images/streamtube_ex1.png" src="_images/streamtube_ex1.png" />
<p class="caption">Stream tubes (Vtk backend).</p>
</div>
<p>Finally, we illustrate the <tt class="docutils literal"><span class="pre">streamribbon</span></tt> command:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">streamribbon</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">w</span><span class="p">,</span> <span class="n">sx</span><span class="p">,</span> <span class="n">sy</span><span class="p">,</span> <span class="n">sz</span><span class="p">,</span>
             <span class="n">ribbonwidth</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span>
             <span class="n">daspect</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span>
             <span class="n">view</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
             <span class="n">axis</span><span class="o">=</span><span class="s">&#39;tight&#39;</span><span class="p">,</span>
             <span class="n">shading</span><span class="o">=</span><span class="s">&#39;interp&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Figure <a class="reference internal" href="#fig-streamribbon-ex1"><em>Stream ribbons (VTK backend).</em></a> shows the resulting stream ribbons.</p>
<div class="figure" id="fig-streamribbon-ex1">
<img alt="_images/streamribbon_ex1.png" src="_images/streamribbon_ex1.png" />
<p class="caption">Stream ribbons (VTK backend).</p>
</div>
</div>
<div class="section" id="bar-charts">
<h2>Bar Charts<a class="headerlink" href="#bar-charts" title="Permalink to this headline">¶</a></h2>
<p>Easyviz also supports a unified interface to simple bar charts.
Here is a simple example for displaying tabular values, with one
bar for each data point:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">scitools.std</span> <span class="kn">import</span> <span class="o">*</span>
<span class="n">languages</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;C&#39;</span><span class="p">,</span> <span class="s">&#39;Java&#39;</span><span class="p">,</span> <span class="s">&#39;C++&#39;</span><span class="p">,</span> <span class="s">&#39;PHP&#39;</span><span class="p">,</span> <span class="s">&#39;VB&#39;</span><span class="p">,</span> <span class="s">&#39;C#&#39;</span><span class="p">,</span> <span class="s">&#39;Python&#39;</span><span class="p">,</span>
             <span class="s">&#39;Perl&#39;</span><span class="p">,</span> <span class="s">&#39;JavaScript&#39;</span><span class="p">]</span>
<span class="n">ratings</span> <span class="o">=</span> <span class="p">[</span><span class="mi">18</span><span class="p">,</span> <span class="mi">18</span><span class="p">,</span> <span class="mf">9.7</span><span class="p">,</span> <span class="mf">9.7</span><span class="p">,</span> <span class="mf">6.4</span><span class="p">,</span> <span class="mf">4.4</span><span class="p">,</span> <span class="mf">4.2</span><span class="p">,</span> <span class="mf">3.6</span><span class="p">,</span> <span class="mf">2.5</span><span class="p">]</span>
<span class="n">bar</span><span class="p">(</span><span class="n">ratings</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">,</span>
    <span class="n">barticks</span><span class="o">=</span><span class="n">languages</span><span class="p">,</span>
    <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;Ratings in percent (TIOBE Index, April 2010)&#39;</span><span class="p">,</span>
    <span class="n">axis</span><span class="o">=</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">languages</span><span class="p">),</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">20</span><span class="p">],</span>
    <span class="n">hardcopy</span><span class="o">=</span><span class="s">&#39;tmp.eps&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The bar chart illustrates the data in the <tt class="docutils literal"><span class="pre">ratings</span></tt> list. These data
correspond to the names in <tt class="docutils literal"><span class="pre">languages</span></tt>.</p>
<div class="figure">
<img alt="_images/pyranking.png" src="_images/pyranking.png" />
<p class="caption">A simple bar chart illustrating the popularity of common programming languages.</p>
</div>
<p>One may display groups of bars. The data can then be put in a matrix,
where rows (1st index) correspond to the groups the columns to the
data within one group:</p>
<div class="highlight-python"><pre>data = [[ 0.15416284  0.7400497   0.26331502]
        [ 0.53373939  0.01457496  0.91874701]
        [ 0.90071485  0.03342143  0.95694934]
        [ 0.13720932  0.28382835  0.60608318]]
bar(data,
    barticks=['group 1', 'group 2', 'group 3', 'group 4'],
    legend=['bar 1', 'bar 2', 'bar 3'],
    axis=[-1, data.shape[0], 0, 1.3],
    ylabel='Normalized CPU time',
    title='Bars from a matrix, now with more annotations')</pre>
</div>
<p>When the names of the groups (barticks) are quite long, rotating them
90 degrees is preferable, and this is done by the keyword
argument <tt class="docutils literal"><span class="pre">rotated_barticks=True</span></tt>.</p>
<p>The demo program in <tt class="docutils literal"><span class="pre">examples/bar_demo.py</span></tt> contains additional examples
and features.</p>
</div>
</div>
<div class="section" id="backends">
<h1>Backends<a class="headerlink" href="#backends" title="Permalink to this headline">¶</a></h1>
<p>As we have mentioned earlier, Easyviz is just a unified interface to
other plotting packages, which we refer to as backends. We have
currently implemented backends for Gnuplot, Grace, OpenDX, Matlab,
Matplotlib, Pmw.Blt, Veusz, VisIt, and VTK. Some are more early in
developement than others, like the backends for OpenDx and VisIt.</p>
<p>Because of limitations in many of the plotting packages, not all
features in Easyviz are supported by each of the backends.  Gnuplot
has (at the time of this writing) no support for visualization of 3D
vector fields, so this is of course not available in the Gnuplot
backend either.</p>
<p>Some supported visualization programs are commented on below.</p>
<p><em>Gnuplot.</em> Gnuplot is a command-driven interactive or scripted
plotting utility that works on a wide variety of platforms. Gnuplot
supports many types of plots in both 2D and 3D, including curve plots,
contour plots, vector plots, and surface plots.  3D scalar and vector
fields are not supported. To access Gnuplot from Python and send NumPy
arrays to Gnuplot, we use the Python module <tt class="docutils literal"><span class="pre">Gnuplot</span></tt>.</p>
<p><em>Matlab.</em> Many view Matlab as the de facto standard for making curves
and plots of 2D scalar/vector fields.</p>
<p><em>Matplotlib.</em> Matplotlib is now quickly gaining wide popularity in
the scientific Python community and has established itself as the de
facto standard for curve plotting and 2D contour and (recently) surface
plotting. The interface to Matplotlib is Matlab-insipired, and
different backends are used to create the plots: Gtk, Tk, WxWidgets
and many more.  (Since Easyviz and Matplotlib haver very similar
Matlab-style syntax, Easyviz is just a thin layer on top of Matplotlib
to enable Matplotlib to be used with the Easyviz unified syntax.)
Matplotlib is now a comprehensive package with lots of tuning
possibilities that Easyviz does not support - but one can fetch the
underlying Matplotlib from Easyviz and call all the functionality of
Matplotlib directly.</p>
<p><em>Grace.</em> Grace is a highly interactive curve plotting program on the
Unix/X11 platform which has been popular for many years. It does not
support 2D or 3D scalar or vector fields. However, it has a lot of
functionality for computing with curves and adjusting/fine-tuning
plots interactively.</p>
<p><em>PyX.</em> PyX is a Python package for the creation of PostScript and
PDF files. It combines an abstraction of the PostScript drawing model
with a TeX/LaTeX interface. Complex tasks like 2d and 3d plots in
publication-ready quality are built out of these primitives.</p>
<p><em>Pmw.Blt.Graph.</em> Pmw (Python Mega Widgets) extends the Tkinter
package with more sophisticated widgets, included an interactive
widget for curve plotting. This widget is based on the BLT package
(an extension of Tk written in C).
The BLT backend offers currenlty only basic plotting functionality.</p>
<p><em>Veusz.</em> From <a class="reference external" href="http://home.gna.org/veusz">Veusz homepage</a>: Veusz is a
GUI scientific plotting and graphing package. It is designed to
produce publication-ready Postscript or PDF output. SVG, EMF and
bitmap formats export are also supported. Veusz has a comprehensive
GUI and produces really high-quality plots.</p>
<p><em>VTK.</em> VTK (Visualization ToolKit) is a package primarily aimed at
visualizing 2D and 3D scalar and vector fields by a range of techniques.
VTK is used to achieve 2D and 3D visualizations of the same type as
Matlab offers. However, VTK can do much more (although the Easyviz
commands are restricted to what is typically offered by Matlab).</p>
</div>
<div class="section" id="design">
<h1>Design<a class="headerlink" href="#design" title="Permalink to this headline">¶</a></h1>
<div class="section" id="main-objects">
<h2>Main Objects<a class="headerlink" href="#main-objects" title="Permalink to this headline">¶</a></h2>
<p>All code that is common to all backends is gathered together in a file
called <tt class="docutils literal"><span class="pre">common.py</span></tt>. For each backend there is a separate file where
the backend dependent code is stored. For example, code that are
specific for the Gnuplot backend, are stored in a file called
<tt class="docutils literal"><span class="pre">gnuplot_.py</span></tt> and code specific for the VTK backend are stored in
<tt class="docutils literal"><span class="pre">vtk_.py</span></tt> (note the final underscore in the stem of the filename - all
backend files have this underscore).</p>
<p>Each backend is a subclass of class <tt class="docutils literal"><span class="pre">BaseClass</span></tt>. The <tt class="docutils literal"><span class="pre">BaseClass</span></tt> code
is found in <tt class="docutils literal"><span class="pre">common.py</span></tt> and contains all common code for the backends.
Basically, a backend class extends <tt class="docutils literal"><span class="pre">BaseClass</span></tt> with
rendering capabilities and backend-specific functionality.</p>
<p>The most important method that needs to be implemented in the backend
is the <tt class="docutils literal"><span class="pre">_replot</span></tt> method, which updates the backend and the plot after a
change in the data. Another important method for the backend class is
the <tt class="docutils literal"><span class="pre">hardcopy</span></tt> method, which stores an image of the data in the current
figure to a file.</p>
<p>Inspired by Matlab, the Easyviz interface is organized around figures and
axes. A figure contains an arbitrary number of axes, and the axes can
be placed in arbitrary positions in the figure window. Each figure appears
in a separate window on the screen. The current figure is accessed by
the <tt class="docutils literal"><span class="pre">gcf()</span></tt> call. Similarly, the current axes are accessed by calling
<tt class="docutils literal"><span class="pre">gca()</span></tt>.</p>
<p>It is
natural to have one class for figures and one for axes. Class <tt class="docutils literal"><span class="pre">Figure</span></tt>
contains a dictionary with one (default) or more <tt class="docutils literal"><span class="pre">Axis</span></tt> objects in
addition to several properties such as figure width and height. Class <tt class="docutils literal"><span class="pre">Axis</span></tt>
has another dictionary with the plot data as well as lots of
parameters for colors, text fonts, labels on the axes, hidden surfaces, etc.
For example, when adding an
elevated surface to the current figure, this surface will be
appended to a list in the current <tt class="docutils literal"><span class="pre">Axis</span></tt> object.
Optionally one can add the surface to another <tt class="docutils literal"><span class="pre">Axis</span></tt>
object by specifying the <tt class="docutils literal"><span class="pre">Axis</span></tt> instance as an argument.</p>
<p>All the objects that are to be plotted in a figure such as curves,
surfaces, vectors, and so on, are stored in repsectively classes.  An
elevated surface, for instance, is represented as an instance of class
<tt class="docutils literal"><span class="pre">Surface</span></tt>.  All such classes are subclasses of
<tt class="docutils literal"><span class="pre">PlotProperties</span></tt>. Besides being the base class of all objects that can
be plotted in a figure
(<tt class="docutils literal"><span class="pre">Line</span></tt>,
<tt class="docutils literal"><span class="pre">Surface</span></tt>,
<tt class="docutils literal"><span class="pre">Contours</span></tt>,
<tt class="docutils literal"><span class="pre">VelocityVectors</span></tt>,
<tt class="docutils literal"><span class="pre">Streams</span></tt>,
<tt class="docutils literal"><span class="pre">Volume</span></tt>),
class <tt class="docutils literal"><span class="pre">PlotProperties</span></tt> also stores various properties that are common
to all objects in a figure. Examples include line properties, material
properties, storage arrays for x and y values for <tt class="docutils literal"><span class="pre">Line</span></tt> objects,
and x, y, and z values for 3D objects such as <tt class="docutils literal"><span class="pre">Volume</span></tt>.</p>
<p>The classes mentioned above, i.e., <tt class="docutils literal"><span class="pre">BaseClass</span></tt> with subclasses, class
<tt class="docutils literal"><span class="pre">PlotProperties</span></tt> with subclasses, as well as class <tt class="docutils literal"><span class="pre">Figure</span></tt> and class
<tt class="docutils literal"><span class="pre">Axis</span></tt> constitute the most important classes in the Easyviz interface.
Other less important classes are <tt class="docutils literal"><span class="pre">Camera</span></tt>, <tt class="docutils literal"><span class="pre">Light</span></tt>, <tt class="docutils literal"><span class="pre">Colorbar</span></tt>, and
<tt class="docutils literal"><span class="pre">MaterialProperties</span></tt>.</p>
<p>All the classes in <tt class="docutils literal"><span class="pre">common.py</span></tt> follows a convention where class parameters
are set by a <tt class="docutils literal"><span class="pre">setp</span></tt> method and read by a <tt class="docutils literal"><span class="pre">getp</span></tt> method. For
example, we can set the limits on the <img class="math" src="_images/math/26eeb5258ca5099acf8fe96b2a1049c48c89a5e6.png" alt="x"/> axis by using the <tt class="docutils literal"><span class="pre">setp</span></tt>
method in a <tt class="docutils literal"><span class="pre">Axis</span></tt> instance:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">ax</span> <span class="o">=</span> <span class="n">gca</span><span class="p">()</span>                  <span class="c"># get current axis</span>
<span class="n">ax</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="n">xmin</span><span class="o">=-</span><span class="mi">2</span><span class="p">,</span> <span class="n">xmax</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
<p>To extract the values of these limits we can write</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">xmin</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xmin&#39;</span><span class="p">)</span>
<span class="n">xmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xmax&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Normal use will seldom involve <tt class="docutils literal"><span class="pre">setp</span></tt> and <tt class="docutils literal"><span class="pre">getp</span></tt> functions, since most
users will apply the Matlab-inspired interface and set, e.g., the
limits by</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">xlim</span><span class="p">([</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="installation">
<h1>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h1>
<p>Easyviz comes with the SciTools package, so to install Easyviz, you
just go to the <tt class="docutils literal"><span class="pre">scitools</span></tt> folder and run</p>
<div class="highlight-python"><pre>Unix/DOS&gt; python setup.py install</pre>
</div>
<p>Easyviz is reached as the package <tt class="docutils literal"><span class="pre">scitools.easyviz</span></tt> and can be
imported in several ways (see the paragraph heading
&#8220;Importing Just Easyviz&#8221; in the Tutorial).</p>
<p>Easyviz will not work unless you have one or more plotting programs
correctly installed. Below, we have collected some information on installing
various programs. This information is in a very preliminary and incomplete
stage.</p>
<p>Please check your plotting program independently of Easyviz, as
described in the <em>Check Your Backends!</em> section of the <em>Troubleshooting</em>
chapter, if you encounter strange errors during Easyviz plotting.</p>
<div class="section" id="installing-gnuplot">
<h2>Installing Gnuplot<a class="headerlink" href="#installing-gnuplot" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="linux-unix">
<h2>Linux/Unix<a class="headerlink" href="#linux-unix" title="Permalink to this headline">¶</a></h2>
<p><em>Compile from Source.</em> Gnuplot can be downloaded from gnuplot.sourceforge.net. It builds
easily on most Unix systems. You also need the <tt class="docutils literal"><span class="pre">Gnuplot</span></tt> Python
module, which can be obtained from <tt class="docutils literal"><span class="pre">gnuplot-py.sourceforge.net</span></tt>.</p>
<p><em>Debian/Ubuntu.</em> Prebuilt versions are available for Debian/Ubuntu:
run</p>
<div class="highlight-python"><pre>apt-get install gnuplot gnuplot-x11 python-gnuplot</pre>
</div>
</div>
<div class="section" id="windows">
<h2>Windows<a class="headerlink" href="#windows" title="Permalink to this headline">¶</a></h2>
<p>On Windows, one can either use Gnuplot under Cygwin or use a precompiled
binary from sourgeforce.net.</p>
<p><em>Using the Gnuplot Cygwin package.</em> In this case there are two things that needs to be changed in the
<tt class="docutils literal"><span class="pre">gp_cygwin.py</span></tt> file in the top-level directory of the <tt class="docutils literal"><span class="pre">Gnuplot.py</span></tt>
source tree. First you need to change the <tt class="docutils literal"><span class="pre">gnuplot_command</span></tt> variable
to <tt class="docutils literal"><span class="pre">gnuplot</span></tt> instead of <tt class="docutils literal"><span class="pre">pgnuplot.exe</span></tt>. Then you should change the
<tt class="docutils literal"><span class="pre">default_term</span></tt> variable to <tt class="docutils literal"><span class="pre">x11</span></tt> instead of <tt class="docutils literal"><span class="pre">windows</span></tt> since the
Gnuplot Cygwin package is not compiled with the Windows
terminal. Finally, install <tt class="docutils literal"><span class="pre">Gnuplot.py</span></tt> (<tt class="docutils literal"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></tt>)
and launch X11 by running <tt class="docutils literal"><span class="pre">startx</span></tt> from a Cygwin prompt. Try to run
the <tt class="docutils literal"><span class="pre">test.py</span></tt> script that comes with <tt class="docutils literal"><span class="pre">Gnuplot.py</span></tt>. If everything
works, Easyviz can use Gnuplot.</p>
<p><em>Using Gnuplot Binaries.</em> First download the Gnuplot 4.2.4 binaries for Windows (or a newer version)
A possible URL is</p>
<div class="highlight-python"><pre>http://prdownloads.sourceforge.net/sourceforge/gnuplot/gp424win32.zip</pre>
</div>
<p>The zip file may have another name for a newer version of Gnuplot on
Windows.</p>
<p>Then unzip the <tt class="docutils literal"><span class="pre">gp424win32.zip</span></tt> file to the folder</p>
<div class="highlight-python"><pre>C:\gnuplot</pre>
</div>
<p>Add the folder name</p>
<div class="highlight-python"><pre>C:\gnuplot\bin</pre>
</div>
<p>to the <tt class="docutils literal"><span class="pre">PATH</span></tt> environment variable (this is done in a graphical interface for
setting environment variables).</p>
<p>Check out the latest SVN revision of the Python interface to
Gnuplot, which is the Python module file <tt class="docutils literal"><span class="pre">Gnuplot.py</span></tt>:</p>
<div class="highlight-python"><pre>svn co https://gnuplot-py.svn.sourceforge.net/svnroot/gnuplot-py/trunk/gnuplot-py</pre>
</div>
<p>Install <tt class="docutils literal"><span class="pre">Gnuplot.py</span></tt>:</p>
<div class="highlight-python"><pre>cd gnuplot-py
python setup.py bdist_wininst
dist\gnuplot-py-1.8+.win32.exe</pre>
</div>
<p>Check out the latest SVN revision of SciTools:</p>
<div class="highlight-python"><pre>svn co http://scitools.googlecode.com/svn/trunk/ scitools</pre>
</div>
<p>Install SciTools:</p>
<div class="highlight-python"><pre>cd scitools
python setup.py bdist_wininst
dist\SciTools-0.4.win32.exe</pre>
</div>
</div>
<div class="section" id="installing-matplotlib">
<h2>Installing Matplotlib<a class="headerlink" href="#installing-matplotlib" title="Permalink to this headline">¶</a></h2>
<p>This is normally just a matter of</p>
<div class="highlight-python"><pre>python setup.py install</pre>
</div>
<p>in the root directory of the Matplotlib code.</p>
<p><em>Debian/Ubuntu.</em> Prebuilt versions are available for Debian/Ubuntu:
run</p>
<div class="highlight-python"><pre>apt-get install python-matplotlib dvipng</pre>
</div>
<p><em>Windows.</em> You can download prebuilt binaries from the Matplotlib home page.</p>
</div>
</div>
<div class="section" id="troubleshooting">
<h1>Troubleshooting<a class="headerlink" href="#troubleshooting" title="Permalink to this headline">¶</a></h1>
<div class="section" id="can-i-perform-a-diagnostic-test-of-easyviz">
<h2>Can I Perform a Diagnostic Test of Easyviz?<a class="headerlink" href="#can-i-perform-a-diagnostic-test-of-easyviz" title="Permalink to this headline">¶</a></h2>
<p>Yes. It is wise to perform a diagnostic test before reporting any error
or trouble to the SciTools maintainers. Find the source folder of SciTools
and go to the <tt class="docutils literal"><span class="pre">misc</span></tt> subfolder. Run</p>
<div class="highlight-python"><pre>python diagonstic.py</pre>
</div>
<p>On the screen, you can see what you have of working software that Easyviz
may use. You do not need to see &#8220;ok&#8221; after each test, but at least
one plotting program must be properly installed. Include the detailed
diagonstics in the <tt class="docutils literal"><span class="pre">scitools_diagnostic.log</span></tt> file as attachment in any
mail to the SciTools developers.</p>
</div>
<div class="section" id="the-plot-window-disappears-immediately">
<h2>The Plot Window Disappears Immediately<a class="headerlink" href="#the-plot-window-disappears-immediately" title="Permalink to this headline">¶</a></h2>
<p>Depending on the backend used for plotting with Easyviz, the plot
window may be killed when the program terminates. Adding a statement
that makes the program halt provides a remedy:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nb">raw_input</span><span class="p">(</span><span class="s">&#39;Press Return key to quit: &#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The plot window will now stay on the screen until hitting the Enter/Return key.</p>
<p>Another remedy can be to add a <tt class="docutils literal"><span class="pre">show()</span></tt> call at the end of the plotting:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="i-get-strange-errors-saying-something-about-latex">
<h2>I Get Strange Errors Saying Something About LaTeX<a class="headerlink" href="#i-get-strange-errors-saying-something-about-latex" title="Permalink to this headline">¶</a></h2>
<p>You probably run Easyviz with Matplotlib as backend, and you do not
have a working LaTeX installation. Matplotlib applies LaTeX for
improved rendering of legends, titles, and numbers.  The fix is to
turn off the use of LaTeX, which is done by the <tt class="docutils literal"><span class="pre">text.usetex</span></tt>
parameter in the <tt class="docutils literal"><span class="pre">matplotlib</span></tt> section of the configuration file.  Set
this parameter to <tt class="docutils literal"><span class="pre">false</span></tt>. See the subsection &#8220;Setting Parameters in
the Configuration File&#8221; in the section &#8220;Advanced Easyviz Topics&#8221; in
the Easyviz tutorial. The tutorial can be reached from the code.google.com
site or by running pydoc scitools.easyviz. If you use Matplotlib as
default plotting engine, we recommend to have a <tt class="docutils literal"><span class="pre">.scitools.cfg</span></tt>
configuration file in your home folder and that use control the use
of Matplotlib parameters in this file.</p>
<p>Another fix of LaTeX-related problems is to switch to another backend
than Matplotlib.</p>
</div>
<div class="section" id="old-programs-with-2d-scalar-vector-field-plotting-do-not-work">
<h2>Old Programs with 2D Scalar/Vector Field Plotting Do Not Work<a class="headerlink" href="#old-programs-with-2d-scalar-vector-field-plotting-do-not-work" title="Permalink to this headline">¶</a></h2>
<p>SciTools version 0.7 changed the default backend for plotting to
Matplotlib instead of Gnuplot (provided you have Matplotlib and you
run <tt class="docutils literal"><span class="pre">setup.py</span></tt> to install SciTools - binaries for Debian still has
Gnuplot as the plotting engine). Some functionality in Gnuplot, especially
regarding 2D vector/scalar fields, is not yet present in Matplotlib
and/or supported by the Easyviz interface to Matplotlib.
You then need to explicitly run the script with Gnuplot as plottin
engine:</p>
<div class="highlight-python"><pre>python myprogram.py --SCITOOLS_easyviz_backend gnuplot</pre>
</div>
<p>or you must import gnuplot explicitly in the program:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">scitools.std</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">scitools.easyviz.gnuplot_</span> <span class="kn">import</span> <span class="o">*</span>
</pre></div>
</div>
<p>or you can edit the installed <tt class="docutils literal"><span class="pre">scitools.cfg</span></tt> file (&#8220;backend&#8221; keyword
in the &#8220;easyviz&#8221; section), or your local version <tt class="docutils literal"><span class="pre">.scitools.cfg</span></tt> in
your home folder, or maybe the simplest solution is to reinstall
SciTools with Gnuplot as plotting engine:</p>
<div class="highlight-python"><pre>python setup.py install --easyviz_backend gnuplot</pre>
</div>
</div>
<div class="section" id="can-i-easily-turn-off-all-plotting">
<h2>Can I Easily Turn Off All Plotting?<a class="headerlink" href="#can-i-easily-turn-off-all-plotting" title="Permalink to this headline">¶</a></h2>
<p>Yes, this is very convenient when debugging other (non-plotting) parts
of a program. Just write</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">scitools.std</span> <span class="kn">import</span> <span class="o">*</span>
<span class="n">turn_off_plotting</span><span class="p">(</span><span class="nb">globals</span><span class="p">())</span>
</pre></div>
</div>
</div>
<div class="section" id="check-your-backends">
<h2>Check Your Backends!<a class="headerlink" href="#check-your-backends" title="Permalink to this headline">¶</a></h2>
<p>When you encounter a problem with Easyviz plotting, make sure that the
backend works correctly on its own (there may, e.g., be installation
problems with the backend - Easyviz just calls the backend to do the
plotting).</p>
<div class="section" id="gnuplot">
<h3>Gnuplot<a class="headerlink" href="#gnuplot" title="Permalink to this headline">¶</a></h3>
<p>For the Gnuplot backend you can try the following commands in a
terminal window:</p>
<div class="highlight-python"><pre>Unix/DOS&gt; gnuplot
gnuplot&gt; plot sin(x)</pre>
</div>
<p>This should result in a plot of the sine function on the screen.
If this command does not work, Easyviz will not work with the Gnuplot
backend. A common problem is that Gnuplot is installed, but the path
to the Gnuplot executable is not registered in the <tt class="docutils literal"><span class="pre">PATH</span></tt> environment
variable. See the section <em>Installing Gnuplot</em> if you need help with
installing the Gnuplot program and its Python interface.</p>
</div>
<div class="section" id="matplotlib">
<h3>Matplotlib<a class="headerlink" href="#matplotlib" title="Permalink to this headline">¶</a></h3>
<p>The following code tests if you have installed Matplotlib correctly:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">,</span> <span class="mi">101</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>In case of problems, go to the Matplotlib source directory, remove the
<tt class="docutils literal"><span class="pre">build</span></tt> subdirectory, and try a new install with <tt class="docutils literal"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></tt>.</p>
</div>
</div>
<div class="section" id="trouble-with-gnuplot-and-threads">
<h2>Trouble with Gnuplot and Threads<a class="headerlink" href="#trouble-with-gnuplot-and-threads" title="Permalink to this headline">¶</a></h2>
<p>When using the Gnuplot backend, the following error may be encountered:</p>
<div class="highlight-python"><pre>thread.error: can't start new thread</pre>
</div>
<p>A remedy is to create fewer plots, and for animations, update the plot
window less frequently. For example,</p>
<div class="highlight-python"><pre>for i in range(number_of_frames_in_animation):
    &lt;prepare data&gt;
    if i % == 100:     # plot every 100 frames
        &lt;make plot&gt;</pre>
</div>
</div>
<div class="section" id="trouble-with-movie-making">
<h2>Trouble with Movie Making<a class="headerlink" href="#trouble-with-movie-making" title="Permalink to this headline">¶</a></h2>
<p>The call to <tt class="docutils literal"><span class="pre">movie</span></tt> demands that you have video encoders installed.
The legal encoders are <tt class="docutils literal"><span class="pre">mencoder</span></tt>, <tt class="docutils literal"><span class="pre">ffmpeg</span></tt>, <tt class="docutils literal"><span class="pre">mpeg_encode</span></tt>, <tt class="docutils literal"><span class="pre">ppmtompeg</span></tt>,
<tt class="docutils literal"><span class="pre">mpeg2enc</span></tt>, and <tt class="docutils literal"><span class="pre">convert</span></tt>. Some of these also require additional
software to be installed.</p>
<p>To install (e.g.) <tt class="docutils literal"><span class="pre">convert</span></tt>, you need to install the ImageMagick
software suite, since <tt class="docutils literal"><span class="pre">convert</span></tt> is a part of that package. ImageMagick
is easy to install on most platforms. The <tt class="docutils literal"><span class="pre">ppmtompeg</span></tt> encoder is a part
of the Netpbm software, while <tt class="docutils literal"><span class="pre">mpeg2enc</span></tt> is a part of <tt class="docutils literal"><span class="pre">mjpegtools</span></tt>.</p>
<p>On Linux Ubuntu you can issue the following installation command to install most of the available encoders for the <tt class="docutils literal"><span class="pre">movie</span></tt> function:</p>
<div class="highlight-python"><pre>Unix&gt; sudo apt-get install mencoder ffmpeg libavcodec-unstripped-51 netpbm mjpegtools imagemagick</pre>
</div>
<p>When something goes wrong with the movie making, check the output in
the terminal window. By default, Easyviz prints the command that makes
the movie. You can manually copy this command and run it again to start
finding out what can be wrong. Just switching to a different encoder can be
a quick remedy. The switch is done with the <tt class="docutils literal"><span class="pre">encoder</span></tt> keyword argument
to <tt class="docutils literal"><span class="pre">movie</span></tt>, e.g.,</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># make animated GIF movie in the file tmpmovie.gif:</span>
<span class="n">movie</span><span class="p">(</span><span class="s">&#39;tmp_*.png&#39;</span><span class="p">,</span> <span class="n">encoder</span><span class="o">=</span><span class="s">&#39;convert&#39;</span><span class="p">,</span> <span class="n">fps</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
      <span class="n">output_file</span><span class="o">=</span><span class="s">&#39;tmpmovie.gif&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="i-get-thread-errors-with-gnuplot">
<h2>I Get Thread Errors with Gnuplot<a class="headerlink" href="#i-get-thread-errors-with-gnuplot" title="Permalink to this headline">¶</a></h2>
<p>When plotting inside a loop, e.g.,</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">some_values</span><span class="p">:</span>
    <span class="o">...</span>
    <span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">X0</span><span class="p">,</span> <span class="s">&#39;r-6&#39;</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span>
         <span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;Xt&#39;</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="s">&#39;My Title&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Gnuplot may lead to thread errors. A remedy is to do some plotting
outside the loop and then only update the data inside the loop:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">X0</span><span class="p">,</span> <span class="s">&#39;r-6&#39;</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span>
     <span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;Xt&#39;</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="s">&#39;My Title&#39;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">some_values</span><span class="p">:</span>
    <span class="o">...</span>
    <span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">X0</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="where-can-i-find-easyviz-documentation">
<h2>Where Can I Find Easyviz Documentation?<a class="headerlink" href="#where-can-i-find-easyviz-documentation" title="Permalink to this headline">¶</a></h2>
<p>There is a verbose Easyviz documentation that mainly focuses on an
introduction to Easyviz (what you read now is a part of that
documentation).</p>
<p>Another useful source of information is the many examples that come
with the SciTools/Easyviz source code. The examples are located in
the <tt class="docutils literal"><span class="pre">examples</span></tt> subfolder of the source.</p>
</div>
<div class="section" id="i-cannot-find-out-how-my-plot-can-be-created">
<h2>I Cannot Find Out How My Plot Can Be Created<a class="headerlink" href="#i-cannot-find-out-how-my-plot-can-be-created" title="Permalink to this headline">¶</a></h2>
<p>Note that Easyviz only support the most basic types of plots:</p>
<blockquote>
<ul class="simple">
<li>y=f(x) curves</li>
<li>bar plots</li>
<li>contour plots of 2D scalar fields</li>
<li>elevated 3D surfaces of 2D scalar fields</li>
<li>3D isosurfaces of 3D scalar fields</li>
<li>arrows reflecting 2D/3D vector fields</li>
<li>streamlines, streamtubes, and streamribbon for 3D vector fields.</li>
</ul>
</blockquote>
<p>For such standard plots you can use Easyviz, otherwise you have to
use a plotting package like Matplotlib, Gnuplot, or VTK directly
from your Python program.</p>
<p>The following Matlab-like commands (functions) are available (but not
supported by all backends):</p>
<blockquote>
<ul class="simple">
<li>autumn,</li>
<li>axes,</li>
<li>axis,</li>
<li>bone,</li>
<li>box,</li>
<li>brighten,</li>
<li>camdolly,</li>
<li>camlight,</li>
<li>camlookat,</li>
<li>campos,</li>
<li>camproj,</li>
<li>camroll,</li>
<li>camtarget,</li>
<li>camup,</li>
<li>camva,</li>
<li>camzoom,</li>
<li>caxis,</li>
<li>cla,</li>
<li>clabel,</li>
<li>clf,</li>
<li>close,</li>
<li>closefig,</li>
<li>closefigs,</li>
<li>colorbar,</li>
<li>colorcube,</li>
<li>colormap,</li>
<li>coneplot,</li>
<li>contour,</li>
<li>contour3,</li>
<li>contourf,</li>
<li>contourslice,</li>
<li>cool,</li>
<li>copper,</li>
<li>daspect,</li>
<li>figure,</li>
<li>fill,</li>
<li>fill3,</li>
<li>flag,</li>
<li>gca,</li>
<li>gcf,</li>
<li>get,</li>
<li>gray,</li>
<li>grid,</li>
<li>hardcopy,</li>
<li>hidden,</li>
<li>hold,</li>
<li>hot,</li>
<li>hsv,</li>
<li>ishold,</li>
<li>isocaps,</li>
<li>isosurface,</li>
<li>jet,</li>
<li>legend,</li>
<li>light,</li>
<li>lines,</li>
<li>loglog,</li>
<li>material,</li>
<li>mesh,</li>
<li>meshc,</li>
<li>openfig,</li>
<li>pcolor,</li>
<li>pink,</li>
<li>plot,</li>
<li>plot3,</li>
<li>prism,</li>
<li>quiver,</li>
<li>quiver3,</li>
<li>reducevolum,</li>
<li>savefig,</li>
<li>semilogx,</li>
<li>semilogy,</li>
<li>set,</li>
<li>shading,</li>
<li>show,</li>
<li><a href="#id1"><span class="problematic" id="id2">slice_</span></a>,</li>
<li>spring,</li>
<li>streamline,</li>
<li>streamribbon,</li>
<li>streamslice,</li>
<li>streamtube,</li>
<li>subplot,</li>
<li>subvolume,</li>
<li>summer,</li>
<li>surf,</li>
<li>surfc,</li>
<li>surfl,</li>
<li>title,</li>
<li>vga,</li>
<li>view,</li>
<li>white,</li>
<li>winter,</li>
<li>xlabel,</li>
<li>ylabel,</li>
<li>zlabel</li>
</ul>
</blockquote>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Easyviz</a><ul>
<li><a class="reference internal" href="#easyviz-documentation">Easyviz Documentation</a></li>
<li><a class="reference internal" href="#guiding-principles">Guiding Principles</a></li>
</ul>
</li>
<li><a class="reference internal" href="#tutorial">Tutorial</a><ul>
<li><a class="reference internal" href="#plotting-a-single-curve">Plotting a Single Curve</a></li>
<li><a class="reference internal" href="#decorating-the-plot">Decorating the Plot</a></li>
<li><a class="reference internal" href="#plotting-multiple-curves">Plotting Multiple Curves</a></li>
<li><a class="reference internal" href="#controlling-line-styles">Controlling Line Styles</a></li>
<li><a class="reference internal" href="#interactive-plotting-sessions">Interactive Plotting Sessions</a></li>
<li><a class="reference internal" href="#making-animations">Making Animations</a></li>
<li><a class="reference internal" href="#advanced-easyviz-topics">Advanced Easyviz Topics</a></li>
</ul>
</li>
<li><a class="reference internal" href="#visualization-of-scalar-fields">Visualization of Scalar Fields</a><ul>
<li><a class="reference internal" href="#elevated-surface-plots">Elevated Surface Plots</a></li>
<li><a class="reference internal" href="#contour-plots">Contour Plots</a></li>
<li><a class="reference internal" href="#pseudocolor-plots">Pseudocolor Plots</a></li>
<li><a class="reference internal" href="#isosurface-plots">Isosurface Plots</a></li>
<li><a class="reference internal" href="#volumetric-slice-plot">Volumetric Slice Plot</a></li>
</ul>
</li>
<li><a class="reference internal" href="#visualization-of-vector-fields">Visualization of Vector Fields</a><ul>
<li><a class="reference internal" href="#quiver-plots">Quiver Plots</a></li>
<li><a class="reference internal" href="#stream-plots">Stream Plots</a></li>
<li><a class="reference internal" href="#bar-charts">Bar Charts</a></li>
</ul>
</li>
<li><a class="reference internal" href="#backends">Backends</a></li>
<li><a class="reference internal" href="#design">Design</a><ul>
<li><a class="reference internal" href="#main-objects">Main Objects</a></li>
</ul>
</li>
<li><a class="reference internal" href="#installation">Installation</a><ul>
<li><a class="reference internal" href="#installing-gnuplot">Installing Gnuplot</a></li>
<li><a class="reference internal" href="#linux-unix">Linux/Unix</a></li>
<li><a class="reference internal" href="#windows">Windows</a></li>
<li><a class="reference internal" href="#installing-matplotlib">Installing Matplotlib</a></li>
</ul>
</li>
<li><a class="reference internal" href="#troubleshooting">Troubleshooting</a><ul>
<li><a class="reference internal" href="#can-i-perform-a-diagnostic-test-of-easyviz">Can I Perform a Diagnostic Test of Easyviz?</a></li>
<li><a class="reference internal" href="#the-plot-window-disappears-immediately">The Plot Window Disappears Immediately</a></li>
<li><a class="reference internal" href="#i-get-strange-errors-saying-something-about-latex">I Get Strange Errors Saying Something About LaTeX</a></li>
<li><a class="reference internal" href="#old-programs-with-2d-scalar-vector-field-plotting-do-not-work">Old Programs with 2D Scalar/Vector Field Plotting Do Not Work</a></li>
<li><a class="reference internal" href="#can-i-easily-turn-off-all-plotting">Can I Easily Turn Off All Plotting?</a></li>
<li><a class="reference internal" href="#check-your-backends">Check Your Backends!</a><ul>
<li><a class="reference internal" href="#gnuplot">Gnuplot</a></li>
<li><a class="reference internal" href="#matplotlib">Matplotlib</a></li>
</ul>
</li>
<li><a class="reference internal" href="#trouble-with-gnuplot-and-threads">Trouble with Gnuplot and Threads</a></li>
<li><a class="reference internal" href="#trouble-with-movie-making">Trouble with Movie Making</a></li>
<li><a class="reference internal" href="#i-get-thread-errors-with-gnuplot">I Get Thread Errors with Gnuplot</a></li>
<li><a class="reference internal" href="#where-can-i-find-easyviz-documentation">Where Can I Find Easyviz Documentation?</a></li>
<li><a class="reference internal" href="#i-cannot-find-out-how-my-plot-can-be-created">I Cannot Find Out How My Plot Can Be Created</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="index.html"
                        title="previous chapter">Welcome to Easyviz Documentation!</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/tmp_easyviz.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="index.html" title="Welcome to Easyviz Documentation!"
             >previous</a> |</li>
        <li><a href="index.html">Easyviz Documentation v1.0 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2010, H. P. Langtangen and J. H. Ring.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.3.
    </div>
  </body>
</html>